WCF自定义userNamePasswordValidation未找到类型

时间:2013-05-01 15:28:19

标签: wcf passwords username

我使用自定义用户名和密码验证创建了一个简单的测试wcf服务。当我启动该服务时,我收到此错误:“无法从程序集'BBT.Sunet.ServiceFassade.WebServices'加载类型'BBT.Sunet.ServiceFassade.WebServices.MyBasicAuthentication'。” 这是堆栈跟踪:

  

[TypeLoadException:无法加载类型   'BBT.Sunet.ServiceFassade.WebServices.MyBasicAuthentication'来自   程序集'BBT.Sunet.ServiceFassade.WebServices'。]   System.RuntimeTypeHandle.GetTypeByName(String name,Boolean   throwOnError,Boolean ignoreCase,Boolean reflectionOnly,   StackCrawlMarkHandle stackMark,Boolean loadTypeFromPartialName,   ObjectHandleOnStack类型)+0
  System.RuntimeTypeHandle.GetTypeByName(String name,Boolean   throwOnError,Boolean ignoreCase,Boolean reflectionOnly,   StackCrawlMark&安培; stackMark,Boolean loadTypeFromPartialName)+95
  System.RuntimeType.GetType(String typeName,Boolean throwOnError,   Boolean ignoreCase,Boolean reflectionOnly,StackCrawlMark& stackMark)   +54 System.Type.GetType(String typeName,Boolean throwOnError)+59 System.ServiceModel.Configuration.UserNameServiceElement.ApplyConfiguration(UserNamePasswordServiceCredential   userName)+300
  System.ServiceModel.Configuration.ServiceCredentialsElement.ApplyConfiguration(ServiceCredentials   行为)+88
  System.ServiceModel.Configuration.ServiceCredentialsElement.CreateBehavior()   +163 System.ServiceModel.Description.ConfigLoader.LoadBehaviors(ServiceModelExtensionCollectionElement 1 behaviorElement, KeyedByTypeCollection 1行为,布尔值   commonBehaviors)+12299640
  System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase   host,ServiceDescription描述,ServiceElement serviceElement,   Action`1 addBaseAddress)+12364511
  System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader   configLoader,ServiceDescription描述,ServiceElement   serviceSection)+67
  System.ServiceModel.ServiceHostBase.ApplyConfiguration()+108
  System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection   baseAddresses)+192
  System.ServiceModel.ServiceHost.InitializeDescription(类型   serviceType,UriSchemeKeyedCollection baseAddresses)+49
  System.ServiceModel.ServiceHost..ctor(类型serviceType,Uri []   baseAddresses)+151
  System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(类型   serviceType,Uri [] baseAddresses)+30
  System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(字符串   constructorString,Uri [] baseAddresses)+422
  System.ServiceModel.HostingManager.CreateService(字符串   normalizedVirtualPath)+1461
  System.ServiceModel.HostingManager.ActivateService(字符串   normalizedVirtualPath)+44
  System.ServiceModel.HostingManager.EnsureServiceAvailable(字符串   normalizedVirtualPath)+651

     

[ServiceActivationException:该服务   '/BBT.Sunet.ServiceFassade.WebServices/Service1.svc'不能   由于编译期间的异常而激活。例外   消息是:无法加载类型   'BBT.Sunet.ServiceFassade.WebServices.MyBasicAuthentication'来自   程序集'BBT.Sunet.ServiceFassade.WebServices'..]
  System.Runtime.AsyncResult.End(IAsyncResult result)+688590
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult的   结果)+190
  System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult的   ar)+310694
  System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult的   ar)+94

这是服务:

Public Class Service1
Implements IService1

''' <summary>
''' Test
''' </summary>
Public Sub New()
End Sub

''' <summary>
''' Test
''' </summary>
Public Function GetData(ByVal aValue As Integer) As String Implements IService1.GetData
    Return String.Format(CultureInfo.CurrentCulture, "You entered: {0}", aValue)
End Function

使用此web.config:

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="BasicAuthBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="BBT.Sunet.ServiceFassade.WebServices.MyBasicAuthentication, BBT.Sunet.ServiceFassade.WebServices" />
      </serviceCredentials>
    </behavior>
    <behavior name="WinAuthBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>
    <binding name="BasicAuthBinding">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" />
        <transport clientCredentialType="None" />
      </security>
    </binding>
    <binding name="WinAuthBinding">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>      
  <service behaviorConfiguration="BasicAuthBehavior" name="BBT.Sunet.ServiceFassade.WebServices.Service1">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicAuthBinding"
      contract="BBT.Sunet.ServiceFassade.WebServices.IService1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

这是UserNamePasswordValidator:

Public Class MyBasicAuthentication
Inherits UserNamePasswordValidator

Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
    If Not (userName.Equals("user") AndAlso password.Equals("password")) Then
        Throw New FaultException("Incorrect Login!")
    End If
End Sub

结束班

一切都在同一个集会中。我使用本地IIS进行调试。我有另一个wcf服务,也在这个IIS上使用基本身份验证,所以IIS配置应该没问题。我将所有内容与工作服务进行了比较,但我没有发现错误。有人能帮助我吗?

0 个答案:

没有答案