WCF错误:调用者没有通过服务进行身份validation

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

调用者未被服务authentication

我正在使用wsHttpBinding 。 我不确定服务期待什么样的身份validation?

 <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> 

更新如果我更改绑定到IIS 7.0托pipe,Windows 2008服务器上<endpoint "basicHttpBinding" ... /> (从wsHttpBinding)它工作

如果使用basicHttpBinding,则将端点安全性configuration为“无”,并将clientCredintialType传输为“无”。

 <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> 

此外,请确保IIS中的身份validation方法启用匿名访问

我知道了。

如果你想使用wshttpbinding,你需要添加Windows凭据如下。

 svc.ClientCredentials.Windows.ClientCredential.UserName = "abc"; svc.ClientCredentials.Windows.ClientCredential.Password = "xxx"; 

谢谢

你有没有尝试过使用basicHttpBinding而不是wsHttpBinding? 如果不需要任何身份validation,并且不需要Ws- *实现,那么使用普通的basicHttpBinding可能会更好。 WsHttpBinding为消息安全和authentication实现WS-Security。

在你的虚拟目录中设置匿名访问

将以下凭据写入您的服务

 ADTService.ServiceClient adtService = new ADTService.ServiceClient(); adtService.ClientCredentials.Windows.ClientCredential.UserName="windowsuseraccountname"; adtService.ClientCredentials.Windows.ClientCredential.Password="windowsuseraccountpassword"; adtService.ClientCredentials.Windows.ClientCredential.Domain="windowspcname"; 

之后,你打电话给你的web服务方法。

如果您使用的是像我这样的自我托pipe网站,避免此问题的方法(如上所述)是在主机和客户端都规定wsHttpBinding安全模式= NONE。

在客户端和主机上创build绑定时,可以使用以下代码:

  Dim binding as System.ServiceModel.WSHttpBinding binding= New System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None) 

要么

  System.ServiceModel.WSHttpBinding binding binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None); 

我们遇到了一个奇怪的问题,WCF服务所在的文件夹有一些导致问题的权限。

如果需要在webconfig中指定域(它确认客户端使用的用户名和密码),你可以把它放在system.serviceModel服务服务部分:

 <identity> <servicePrincipalName value="example.com" /> </identity> 

并在客户端指定域和用户名和密码:

  client.ClientCredentials.Windows.ClientCredential.Domain = "example.com"; client.ClientCredentials.Windows.ClientCredential.UserName = "UserName "; client.ClientCredentials.Windows.ClientCredential.Password = "Password"; 

我能够通过以下步骤解决共享问题:

  1. 转到IIS – > 站点 – > 您的站点 – >
  2. function视图窗格 – > 身份validation
  3. 匿名身份validation设置为禁用
  4. Windows身份validation设置为启用

在这里输入图像说明

如果客户端与服务器位于不同的域中,可能会导致这种情况。

当我从我的PC(客户端)testing我的应用程序到我的(云)testing服务器时,我遇到了这个问题,我想到的最简单的解决scheme是设置一个vpn。

为什么不能只为wsHttpBinding(“none”而不是“message”或“transport”)移除安全设置?