.net WCF 错误:调用者未经服务验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/284538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF error: The caller was not authenticated by the service
提问by
I am trying to access my WCF service on a server from my client console application for testing. I am getting the following error:
我正在尝试从客户端控制台应用程序访问服务器上的 WCF 服务以进行测试。我收到以下错误:
The caller was not authenticated by the service
调用者未经服务验证
I am using wsHttpBinding. I'm not sure what kind of authentication the service is expecting?
我正在使用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>
UpdateIt works if I change my binding to <endpoint "basicHttpBinding" ... />(from wsHttpBinding)
on the IIS 7.0 hosted, windows 2008 server
更新如果我<endpoint "basicHttpBinding" ... />在 IIS 7.0 托管的 windows 2008 服务器上将绑定更改为(从 wsHttpBinding),它会起作用
回答by Michael Kniskern
If you use basicHttpBinding, configure the endpoint security to "None" and transport clientCredintialType to "None."
如果您使用 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>
Also, make sure the directory Authentication Methods in IIS to Enable Anonymous access
另外,请确保 IIS 中的目录身份验证方法启用匿名访问
回答by Michael Kniskern
I got it.
我知道了。
If you want to use wshttpbinding, u need to add windows credentials as below.
如果您想使用 wshttpbinding,您需要添加 Windows 凭据,如下所示。
svc.ClientCredentials.Windows.ClientCredential.UserName = "abc";
svc.ClientCredentials.Windows.ClientCredential.Password = "xxx";
thanks
谢谢
回答by Ta01
Have you tried using basicHttpBinding instead of wsHttpBinding? If do not need any authentication and the Ws-* implementations are not required, you'd probably be better off with plain old basicHttpBinding. WsHttpBinding implements WS-Security for message security and authentication.
您是否尝试过使用 basicHttpBinding 而不是 wsHttpBinding?如果不需要任何身份验证并且不需要 Ws-* 实现,那么使用普通的旧 basicHttpBinding 可能会更好。WsHttpBinding 为消息安全和身份验证实现了 WS-Security。
回答by kishore
set anonymous access in your virtual directory
在您的虚拟目录中设置匿名访问
write following credentials to your service
将以下凭据写入您的服务
ADTService.ServiceClient adtService = new ADTService.ServiceClient();
adtService.ClientCredentials.Windows.ClientCredential.UserName="windowsuseraccountname";
adtService.ClientCredentials.Windows.ClientCredential.Password="windowsuseraccountpassword";
adtService.ClientCredentials.Windows.ClientCredential.Domain="windowspcname";
after that you call your webservice methods.
之后你调用你的网络服务方法。
回答by Brian
If you're using a self hosted site like me, the way to avoid this problem (as described above) is to stipulate on both the host and client side that the wsHttpBinding security mode = NONE.
如果您使用的是像我这样的自托管站点,则避免此问题的方法(如上所述)是在主机端和客户端都规定 wsHttpBinding 安全模式 = NONE。
When creating the binding, both on the client and the host, you can use this code:
在客户端和主机上创建绑定时,您可以使用以下代码:
Dim binding as System.ServiceModel.WSHttpBinding
binding= New System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None)
or
或者
System.ServiceModel.WSHttpBinding binding
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);
回答by Ajay Shankar
回答by yiannis
This can be caused if the client is in a different domain than the server.
如果客户端与服务器位于不同的域中,则可能会导致这种情况。
I encountered this when testing one of my applications from my PC(client) to my (cloud) testing server and the simplest solution i could think of was setting up a vpn.
我在从我的 PC(客户端)测试我的一个应用程序到我的(云)测试服务器时遇到了这个问题,我能想到的最简单的解决方案是设置一个 vpn。
回答by Nani
I also had the same problem in wsHtppBinding. And I just had to add securitymode pointing to none, that solved my problem and no need to switch to basicHttpBinding. Check Hereand check how to disable WCF security. Check the below config change for reference:
我在wsHtppBinding. 我只需要添加security指向 的模式none,就解决了我的问题,无需切换到basicHttpBinding. 检查此处并检查如何禁用 WCF 安全性。检查以下配置更改以供参考:
<wsHttpBinding>
<binding name="soapBinding">
<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
回答by TruthOf42
We ran into a weird issue where the folder where the WCF service was being hosted from had some permissions that were causing the problem.
我们遇到了一个奇怪的问题,其中托管 WCF 服务的文件夹有一些导致问题的权限。
回答by farhang67
if needed to specify domain(which authecticates username and password that client uses) in webconfig you can put this in system.serviceModel services service section:
如果需要在 webconfig 中指定域(验证客户端使用的用户名和密码),您可以将其放在 system.serviceModel services 服务部分:
<identity>
<servicePrincipalName value="example.com" />
</identity>
and in client specify domain and username and password:
并在客户端指定域和用户名和密码:
client.ClientCredentials.Windows.ClientCredential.Domain = "example.com";
client.ClientCredentials.Windows.ClientCredential.UserName = "UserName ";
client.ClientCredentials.Windows.ClientCredential.Password = "Password";


