none
Erro ao usar userNameAuthentication customizada RRS feed

  • Pergunta

  • Eu segui um exemplo do Israel Aece, mas também li vários parecidos pela web, a seção do serviço no Web.Config esta abaixo, a classe eu herdei de System.IdentityModel.Selectors.UserNamePasswordValidator, mas o erro abaixo aparece, e isso só de clicar no link do arquivo SVC para ver se o serviço esta OK. Acho que tudo o que poderia ter corrigido de configuração eu fiz. parece ser mais um erro relacionado a framework, li que poderia ser sujeira no temporário do ASP.Net, que a instalação do framework estava com problema, entre outras coisas, mas nada funcionou.

    Agradeço antecipadamente a ajuda.

    <system.serviceModel>
      <services>
       <service name="UIService.Logon" behaviorConfiguration="UIService.LogonBehavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="UIService.ILogon">
         <!--
           Upon deployment, the following identity element should be removed or replaced to reflect the 
           identity under which the deployed service runs. If removed, WCF will infer an appropriate identity 
           automatically.
         -->
         <identity>
          <dns value="localhost"/>
         </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       </service>
      </services>
      <behaviors>
       <serviceBehaviors>
        <behavior name="UIService.LogonBehavior">
         <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
         <serviceMetadata httpGetEnabled="true"/>
         <serviceCredentials>
          <userNameAuthentication userNamePasswordValidationMode="Custom"
                      customUserNamePasswordValidatorType="CustomUserValidator"/>
          <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="TrustedPeople"/>
         </serviceCredentials>
         <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
         <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
       </serviceBehaviors>
      </behaviors>
     </system.serviceModel>
    

    Server Error in '/' Application.

    Could not load type 'CustomUserValidator' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.TypeLoadException: Could not load type 'CustomUserValidator' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [TypeLoadException: Could not load type 'CustomUserValidator' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
      System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +0
      System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +64
      System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +58
      System.Type.GetType(String typeName, Boolean throwOnError) +59
      System.ServiceModel.Configuration.UserNameServiceElement.ApplyConfiguration(UserNamePasswordServiceCredential userName) +287
      System.ServiceModel.Configuration.ServiceCredentialsElement.ApplyConfiguration(ServiceCredentials behavior) +94
      System.ServiceModel.Configuration.ServiceCredentialsElement.CreateBehavior() +163
      System.ServiceModel.Description.ConfigLoader.LoadBehaviors(ServiceModelExtensionCollectionElement`1 behaviorElement, KeyedByTypeCollection`1 behaviors, Boolean commonBehaviors) +11150903
      System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress) +188
      System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection) +55
      System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName) +35
      System.ServiceModel.ServiceHostBase.ApplyConfiguration() +69
      System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +190
      System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +32
      System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +139
      System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +28
      System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +331
      System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +11659932
      System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42
      System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
    
    [ServiceActivationException: The service '/Logon.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load type 'CustomUserValidator' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..]
      System.ServiceModel.AsyncResult.End(IAsyncResult result) +11531006
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
      System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278
      System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
      System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    


    Version Information: Microsoft .NET Framework Version:2.0.50727.4408; ASP.NET Version:2.0.50727.5053

    Brandão .NET Developer
    quinta-feira, 13 de janeiro de 2011 23:01

Respostas

  • Boas Brandão,

    Para mencionar um tipo no arquivo de configuração, você precisa colocar o FullName, incluindo o namespace até o arquivo e o nome do Assembly, algo como:

    <userNameAuthentication
        userNamePasswordValidationMode="Custom"
        customUserNamePasswordValidatorType="TeuNamespace.CustomUserValidator, NomeDoAssembly"/>

    http://www.israelaece.com
    • Marcado como Resposta BrandãoMVP sexta-feira, 14 de janeiro de 2011 12:37
    sexta-feira, 14 de janeiro de 2011 00:42
    Moderador

Todas as Respostas

  • Boas Brandão,

    Para mencionar um tipo no arquivo de configuração, você precisa colocar o FullName, incluindo o namespace até o arquivo e o nome do Assembly, algo como:

    <userNameAuthentication
        userNamePasswordValidationMode="Custom"
        customUserNamePasswordValidatorType="TeuNamespace.CustomUserValidator, NomeDoAssembly"/>

    http://www.israelaece.com
    • Marcado como Resposta BrandãoMVP sexta-feira, 14 de janeiro de 2011 12:37
    sexta-feira, 14 de janeiro de 2011 00:42
    Moderador
  • Funcionou,

    Eu fiz várias configurações erradas e a medida que fui corrigindo não voltei esse formato.

    Obrigado.


    Brandão .NET Developer
    sexta-feira, 14 de janeiro de 2011 12:38