WCF错误:服务未对调用方进行身份验证

43 .net security wcf wcf-binding

我试图从我的客户端控制台应用程序访问服务器上的WCF服务进行测试.我收到以下错误:

呼叫者未通过该服务进行身份验证

我在用wsHttpBinding.我不确定服务期望的验证类型是什么?



<behaviors>
  <serviceBehaviors>
    <behavior name="MyTrakerService.MyTrakerServiceBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

更新 如果我<endpoint "basicHttpBinding" ... />在IIS 7.0托管的Windows 2008服务器上更改绑定(来自wsHttpBinding),则它可以正常工作

Mic*_*ern 25

如果使用basicHttpBinding,请将端点安全性配置为"None",并将clientCredintialType传输为"None".

<bindings>
    <basicHttpBinding>
        <binding name="MyBasicHttpBinding">
            <security mode="None">
                <transport clientCredentialType="None" />
            </security>
        </binding>
    </basicHttpBinding>
</bindings>
<services>
    <service behaviorConfiguration="MyServiceBehavior" name="MyService">
        <endpoint 
            binding="basicHttpBinding" 
            bindingConfiguration="MyBasicHttpBinding"
            name="basicEndPoint"    
            contract="IMyService" 
        />
</service>
Run Code Online (Sandbox Code Playgroud)

此外,请确保IIS中的目录身份验证方法启用匿名访问


小智 23

我知道了.

如果要使用wshttpbinding,则需要添加Windows凭据,如下所示.

svc.ClientCredentials.Windows.ClientCredential.UserName = "abc";
svc.ClientCredentials.Windows.ClientCredential.Password = "xxx";
Run Code Online (Sandbox Code Playgroud)

谢谢

  • 你也可能需要域名(.ClientCredentials.Windows.ClientCredential.Domain) (4认同)

kd7*_*kd7 4

您是否尝试过使用 basicHttpBinding 而不是 wsHttpBinding?如果不需要任何身份验证并且不需要 Ws-* 实现,那么使用普通的 basicHttpBinding 可能会更好。WsHttpBinding 实现了 WS-Security 以实现消息安全和身份验证。