【问题标题】:WCF error: The caller was not authenticated by the serviceWCF 错误:调用者未通过服务的身份验证
【发布时间】:2010-09-22 00:32:32
【问题描述】:

我正在尝试从我的客户端控制台应用程序访问服务器上的 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>

更新 如果我将绑定更改为 &lt;endpoint "basicHttpBinding" ... /&gt;(来自 wsHttpBinding),它会起作用 在 IIS 7.0 托管的 windows 2008 服务器上

【问题讨论】:

  • 编辑您的帖子并添加 .config 文件的相关部分。
  • 您尝试使用的 WCF 服务是如何托管的?
  • 如果它托管在 IIS 中,目录安全设置是什么?匿名还是 Windows 集成?
  • 你能标记这个问题的答案吗?您似乎能够解决您的问题。
  • 为我解决的操作是将应用程序池标识从“ApplicationPoolIdentity”更改为“NetworkService”。

标签: .net wcf security wcf-binding


【解决方案1】:

如果您使用 basicHttpBinding,请将端点安全性配置为“None”,并将 clientCredentialType 传输为“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>

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

【讨论】:

  • @KhumeshKumawat 如果需要,您可以创建和验证自己的答案,或者只是验证现有答案之一(即使它不完全是您选择的答案)。您的问题有超过 60,000 次浏览,因此它很重要。它应该得到一个“官方”的回答。
【解决方案2】:

我明白了。

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

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

谢谢

【讨论】:

  • 您可能也需要域 (.ClientCredentials.Windows.ClientCredential.Domain)
  • 我的情况很奇怪。在一台机器上,我可以在没有明确 ClientCredential.Domain 的情况下访问服务,而从另一台机器上,如果没有域,它就无法工作
【解决方案3】:

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

【讨论】:

    【解决方案4】:

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

    将以下凭据写入您的服务

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

    之后你调用你的网络服务方法。

    【讨论】:

    • 附加的域行是我的问题的解决方案,这在下面更可信的答案中没有
    【解决方案5】:

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

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

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

    【讨论】:

      【解决方案6】:

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

      1. 转到 IIS-->站点-->您的站点-->
      2. 功能视图窗格-->身份验证
      3. 匿名身份验证设置为禁用
      4. Windows 身份验证 设置为 启用

      【讨论】:

        【解决方案7】:

        如果需要在 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";
        

        【讨论】:

          【解决方案8】:

          如果客户端与服务器位于不同的域中,则可能会导致此问题。

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

          【讨论】:

            【解决方案9】:

            我在wsHtppBinding 也遇到了同样的问题。我只需要添加指向nonesecurity 模式,就解决了我的问题,无需切换到basicHttpBindingCheck Here 并检查如何禁用 WCF 安全性。检查以下配置更改以供参考:

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

            【讨论】:

              【解决方案10】:

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

              【讨论】:

              • 当有人遇到安全问题时,用“为什么必须使用安全性?”的问题回答他们不是很有建设性的。这是一个合理的问题,假设他们的应用程序需要安全配置,他们需要一个答案,而不是一个愚蠢的问题。
              • 我不同意 - 当您开始使用该领域的任何技术并使用示例项目时,很容易最终会启用大量默认启用的安全功能,而您不一定会问为。
              猜你喜欢
              • 2013-08-21
              • 2018-03-28
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-11-17
              • 2011-11-11
              • 1970-01-01
              相关资源
              最近更新 更多