将基本身份验证添加到Windows服务中托管的WCF服务

时间:2011-09-12 09:47:18

标签: wcf windows-services basic-authentication

如何向Windows服务中托管的WCF服务添加基本身份验证?

我在绑定中添加了一个安全标记,但是当我在浏览器中调用服务URL时,我没有获得身份验证窗口。我做错了什么/我错过了什么?

<bindings>
  <basicHttpBinding>
    <binding name="MyDefaultBinding" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000">
      <readerQuotas maxDepth="500" maxArrayLength="20000000" maxStringContentLength="20000000"/>  
    <security mode="TransportCredentialOnly">
       <transport clientCredentialType="Basic" />
   </security>
    </binding>
  </basicHttpBinding>
</bindings>

1 个答案:

答案 0 :(得分:4)

只访问服务帮助程序页面时,您将无法获得该身份验证窗口。为服务端点配置了身份验证 - 而不是帮助页面或WSDL(那些是“单独的端点”)。

尝试修改配置:

<bindings>
  <customBinding>
    <binding name="securedPages">
      <textMessageEncoding messageVersion="None" />
      <httpsTransport authenticationScheme="Basic" />
    </binding>
  <customBinding>
  <basicHttpBinding>
    <binding name="MyDefaultBinding" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000">
      <readerQuotas maxDepth="500" maxArrayLength="20000000" maxStringContentLength="20000000"/>  
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="securedService">
      <serviceMetadata httpGetEnabled="true" httpGetBinding="customBinding" 
                       httpGetBindingConfiguration="securedPages" />
      <serviceDebug httpHelpPageEnabled="true" httpHelpPageBinding="customBinding" 
                    httpHelpPageBindingConfiguration="securedPages" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="..." behaviorConfiguration="securedService">
    ...
  </service>
</services>