使用System.Web.ApplicationServices.AuthenticationService进行WCF服务身份验证,我无法向成员资格提供程序进行身份验证

时间:2010-09-16 22:56:06

标签: asp.net wcf authentication forms-authentication membership-provider

我正在尝试使用身份验证服务和我的成员资格提供程序进行身份验证。理想情况下,我想打电话给我的会员提供商,但我在击中我的提供商之前就爆炸了。说令牌无法验证。检查我的错误日志,似乎我正在尝试使用Windows身份验证进行身份验证。那不是我打算做的。这是一个带有svc文件的网站。我使用svcUtil并从WSDL生成客户端。我在应用程序中有一个测试页面,我正在使用客户端。它只是一个测试页面,不会被部署。我看到在IIS中检查了集成Windows身份验证,这看起来不正确,但如果我取消选中它,Visual Studio将无法调试。无论如何,我查看事件日志并得到两个错误

Logon Failure:
 Reason:        Unknown user name or bad password
 User Name:    sandagtestuser
 Domain:        
 Logon Type:    8
 Logon Process:    Advapi  
 Authentication Package:    MICROSOFT_AUTHENTICATION_PACKAGE_V1_0
 Workstation Name:    SDD-CK

Logon attempt by: MICROSOFT_AUTHENTICATION_PACKAGE_V1_0
Logon account:  sandagtestuser
Source Workstation: SDD-CK
Error Code: 0xC0000064

以下是web.config中的绑定。请注意我正在尝试使用SSL和HTTPS。这是我第一次尝试WCF安全性

<system.serviceModel>
        <client>
        <endpoint address="https://SDD-CK/ATISServices/Services/AuthService.svc/AuthService"
              binding="basicHttpBinding" bindingConfiguration="userHttps_AuthenticationService"
              contract="AuthenticationService" name="userHttps_AuthenticationService" >
        </endpoint>
    </client>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <behaviors>
<serviceBehaviors>
              <behavior name="ATISServices.AuthServiceBehavior">
                <serviceMetadata httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>

            <binding name="userHttps_AuthenticationService" closeTimeout="00:01:00"
               openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
               allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
               maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
               useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="TransportWithMessageCredential">
                    <transport proxyCredentialType="None" clientCredentialType="None" realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />                       
                </security>
            </binding>
            <binding name="basic_auth_config">
                <security mode="TransportWithMessageCredential">
                    <message clientCredentialType="UserName" />
                </security>
            </binding>
        </basicHttpBinding>

    </bindings>
    <services>

        <service behaviorConfiguration="ATISServices.AuthServiceBehavior"
            name="System.Web.ApplicationServices.AuthenticationService">

            <endpoint binding="basicHttpBinding" bindingName="userHttps" bindingConfiguration="basic_auth_config"
                bindingNamespace="http://asp.net/ApplicationServices/v200"
                contract="System.Web.ApplicationServices.AuthenticationService"
                address="AuthService"/>

            <endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration=""
                contract="IMetadataExchange" />  

        </service>
    </services>
</system.serviceModel>

也许一些WCF大师可以帮助我纠正这个问题。我看到凭据通过事件日志进入服务器,所以我不能太过分了。故障上的实际InnerException消息是At least one security token in the message could not be validated.

最后,这里有一些可能感兴趣的其他web.config设置。

 <system.web.extensions>
    <scripting>
        <webServices>
            <authenticationService enabled="true" requireSSL="true"/>
        </webServices>

    </scripting>
</system.web.extensions>

 <authentication mode="Forms" >
        <forms cookieless="UseCookies" />
    </authentication>

 <membership defaultProvider="KCMembershipProvider">
        <providers>
            <clear/>
            <add
            name="KCMembershipProvider"
            applicationName="/"
            type="zcore.MembershipProvider.KCMembershipProvider, zcore.MembershipProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"  />
        </providers>
    </membership>

此时的任何帮助或提示将不胜感激。我已经与这场斗争了两天。我也在使用证书。我用'makecert'工具制作它们。一个是证书颁发机构,另一个是使用该权威机构的“本地主机”证书。我也使用了httpcfg并将cert thumbprint设置为端口9307,但是当我在服务地址上放置“:9307”时,我得到了主动拒绝连接。我真的很感激这里的任何帮助。

干杯,
〜在圣地亚哥

1 个答案:

答案 0 :(得分:1)

这实际上让它发挥作用。将此添加到服务行为。

 <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="KCMembershipProvider"/>
      </serviceCredentials>