简体   繁体   English

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

[英]WCF error: The caller was not authenticated by the service

I am trying to access my WCF service on a server from my client console application for testing. 我试图从我的客户端控制台应用程序访问服务器上的WCF服务进行测试。 I am getting the following error: 我收到以下错误:

The caller was not authenticated by the service 呼叫者未通过该服务进行身份验证

I am using wsHttpBinding . 我正在使用wsHttpBinding I'm not sure what kind of authentication the service is expecting? 我不确定服务期望的验证类型是什么?



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

Update It works if I change my binding to <endpoint "basicHttpBinding" ... /> (from wsHttpBinding) on the IIS 7.0 hosted, windows 2008 server 更新如果我在IIS 7.0托管的Windows 2008服务器上将绑定更改为<endpoint "basicHttpBinding" ... /> (来自wsHttpBinding),则此方法有效

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中的目录身份验证方法启用匿名访问

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

Have you tried using basicHttpBinding instead of wsHttpBinding? 您是否尝试过使用basicHttpBinding而不是wsHttpBinding? If do not need any authentication and the Ws-* implementations are not required, you'd probably be better off with plain old basicHttpBinding. 如果不需要任何身份验证并且不需要Ws- *实现,那么使用普通的basicHttpBinding可能会更好。 WsHttpBinding implements WS-Security for message security and authentication. WsHttpBinding实现了WS-Security以实现消息安全性和身份验证。

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. 之后,您调用您的Web服务方法。

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

I was able to resolve the shared issue by following below steps: 我可以通过以下步骤解决共享问题:

  1. Go to IIS--> Sites --> Your Site --> 转到IIS - > 站点 - > 您的站点 - >
  2. Features View Pane--> Authentication 功能查看窗格 - > 身份验证
  3. Set Anonymous Authentication to Disabled 匿名身份验证设置为已禁用
  4. Set Windows Authentication to Enabled Windows身份验证设置为已启用

在此输入图像描述

我们遇到了一个奇怪的问题,其中托管WCF服务的文件夹具有导致问题的一些权限。

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服务服务部分:

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

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。

I also had the same problem in wsHtppBinding . 我在wsHtppBinding也遇到了同样的问题。 And I just had to add security mode pointing to none , that solved my problem and no need to switch to basicHttpBinding . 我只需要添加指向none security模式,这解决了我的问题,无需切换到basicHttpBinding Check Here and check how to disable WCF security. 选中此处并检查如何禁用WCF安全性。 Check the below config change for reference: 检查以下配置更改以供参考:

<wsHttpBinding>
    <binding name="soapBinding">
        <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
        </security>
    </binding>
</wsHttpBinding>

为什么你不能完全删除wsHttpBinding的安全设置(“none”而不是“message”或“transport”)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM