【问题标题】:Add basic authentication to WCF Service hosted in a Windows service向 Windows 服务中托管的 WCF 服务添加基本身份验证
【发布时间】:2013-08-17 00:08:42
【问题描述】:

如何向 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>

【问题讨论】:

    标签: wcf windows-services basic-authentication


    【解决方案1】:

    当您仅访问服务帮助页面时,您不会看到该身份验证窗口。身份验证是为服务端点配置的 - 而不是帮助页面或 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>
    

    【讨论】:

      猜你喜欢
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      相关资源
      最近更新 更多