【问题标题】:Requests to wcf service are unauthorized对 wcf 服务的请求未经授权
【发布时间】:2011-08-23 13:24:32
【问题描述】:

我想在我的 asp.net 应用程序中使用 wcf 服务,该应用程序使用集成的 windows 身份验证,但是对我的 Model.svc 的所有请求都是 401 未授权。 如果我将 clientCredentialType="Windows" 更改为 clientCredentialType="Ntlm" 每个请求都未授权 2 次,第 3 次成功。

这是我的 web.config:

<configuration>
  <appSettings>
  </appSettings>
  <connectionStrings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />
  </system.web>
  <!--WCF Configuration-->
  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
    <bindings>
      <webHttpBinding>
        <binding name="WebHttpBinding_IModel">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <client />
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Model">
        <endpoint address="" behaviorConfiguration="JsonBehavior" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IModel" contract="IModel">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="JsonBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
     </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

【问题讨论】:

    标签: asp.net wcf iis windows-authentication


    【解决方案1】:

    2 次未经授权和第三次工作是协议的一部分。这就是 NTLM 身份验证的工作方式。这有问题吗? WCF 就是为处理这种情况而设计的,因此您的 WCF 身份验证调用可以正常工作。

    【讨论】:

    • 我想使用 Windows 身份验证。无论如何...我只是在一个真正的 IIS 上对其进行了测试,它可以正常工作。所以这只是 asp.net 开发服务器和 windows-auth 的问题
    猜你喜欢
    • 1970-01-01
    • 2014-07-08
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 2012-09-04
    相关资源
    最近更新 更多