-->

WCFTestClient HTTP请求是未经授权的客户端身份验证方案“匿名”(WCFTestCli

2019-06-24 04:14发布

我创建了一个WCF服务,并将其部署在服务器上。 当我浏览这个服务它给我?WSDL URL积极响应。 现在我想要测试通过WCF测试客户端服务。 它显示了正确的元数据。 但是,当我尝试从服务调用任何方法,它为我破例?这里有与堆栈跟踪埃罗细节..

HTTP请求是未经授权的客户端身份验证方案“匿名”。 从服务器接收到的认证标头是“协商,NTLM”。

服务器堆栈跟踪:


System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest的请求,响应HttpWebResponse,引发WebException responseException,HttpChannelFactory工厂)
HTTP请求是未经授权的客户端身份验证方案“匿名”。 从服务器接收到的认证标头是“协商,NTLM”。

服务器堆栈跟踪:


System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest的请求,响应HttpWebResponse,引发WebException responseException,HttpChannelFactory工厂)

客户端绑定:

<bindings>
    <wsHttpBinding>
        <binding name="WSHttpBinding_IServiceMagicService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
            allowCookies="false">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
            <security mode="None">
                <transport clientCredentialType="Windows" proxyCredentialType="None"
                    realm="" />
                <message clientCredentialType="Windows" negotiateServiceCredential="true"
                    establishSecurityContext="true" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>

服务器绑定:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_SEOService" closeTimeout="00:10:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="true" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="999524288" maxReceivedMessageSize="655360000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="900000" maxArrayLength="900000" maxBytesPerRead="900000" maxNameTableCharCount="900000" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
      <security mode="None">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
      </security>
    </binding>
    <binding name="WSHttpServiceMagicBinding" closeTimeout="00:10:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="true" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="999524288" maxReceivedMessageSize="655360000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="900000" maxArrayLength="900000" maxBytesPerRead="900000" maxNameTableCharCount="900000"/>
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
      <security mode="None">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

客户端的客户端部分:

<client>
    <endpoint address="http://hydwebd02.solutions.com/GeoService.Saveology.com/ServiceMagicService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IServiceMagicService"
        contract="IServiceMagicService" name="WSHttpBinding_IServiceMagicService" />
</client>

服务器的服务组:

<services>
    <service behaviorConfiguration="GeoService.Saveology.com.CityStateServiceProviderBehavior"
    name="GeoService.Saveology.com.CityStateServiceProvider">
    <endpoint binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_SEOService"
        contract="SEO.Common.ServiceContract.ICityStateService" />
    <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
        contract="IMetadataExchange" />
    </service>
    <service behaviorConfiguration="GeoService.Saveology.com.ServiceMagicServiceProviderBehavior"
    name="GeoService.Saveology.com.ServiceMagicServiceProvider">
    <endpoint binding="wsHttpBinding" bindingConfiguration="WSHttpServiceMagicBinding" 
        contract="SEO.Common.ServiceContract.IServiceMagicService">
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
    </service>
</services>

Answer 1:

我没有过,因为我打电话到服务的安全配置控制,但得到了同样的错误。 我能解决我的客户如下。

  1. 在配置上,建立了安全模式:

     <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> 
  2. 在代码中,设置代理类,允许模拟(我加入一种名为客户参考):

     Customer_PortClient proxy = new Customer_PortClient(); proxy.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 


Answer 2:

我有一个类似的问题,你有没有尝试过:

proxy.ClientCredentials.Windows.AllowedImpersonationLevel =   
          System.Security.Principal.TokenImpersonationLevel.Impersonation;


Answer 3:

我认为这是没有回答,这是一个确切的报价从这里开始 :

WsHttpBinding的将尝试并执行在SSP层的内部谈判。 为了使这项工作成功,你需要允许匿名在IIS中的VDIR。 然后WCF将默认为会借此窗口凭据的SPNEGO。 允许在IIS匿名层没有允许任何人在,它被推迟到WCF堆栈。

我发现这个通过: http://fczaja.blogspot.com/2009/10/http-request-is-unauthorized-with.html

谷歌搜索后: http://www.google.tt/#hl=en&source=hp&q=+The+HTTP+request+is+unauthorized+with+client+authentication+scheme+%27Anonymous



Answer 4:

另一种可能的解决这个错误,我发现。 可能没有回答OP的确切问题,但可以帮助别人谁碰到这个错误信息绊倒。

我使用的WebHttpBinding,以复制下面的行代码创建我的客户:

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Windows" proxyCredentialType="Windows" />
</security>

我必须做:

var binding = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Windows;

以及设置proxy.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;



Answer 5:

我有一个类似的问题,想尽一切上文建议。 然后我试图改变clientCreditialType到基本和一切工作正常。

<basicHttpBinding>
    <binding name="BINDINGNAMEGOESHERE" >
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Basic"></transport>
      </security>
    </binding>
  </basicHttpBinding>


Answer 6:

这是我必须做的得到这个工作。 这意味着:

  1. 自UserNamePasswordValidator(不需要Windows帐户,SQLServer的或ActiveDirectory中 - 你UserNamePasswordValidator可能会对用户名和密码硬编码,或从一个文本文件中,MySQL或任何阅读)。
  2. HTTPS
  3. IIS7
  4. .NET 4.0

我的网站是通过DotNetPanel管理。 它具有虚拟目录的3个安全选项:

  1. 允许匿名访问
  2. 启用基本验证
  3. 启用集成Windows身份验证

只有“允许匿名访问”需要(虽然,通过本身是不够的)。

设置

proxy.ClientCredentials.Windows.AllowedImpersonationLevel =  System.Security.Principal.TokenImpersonationLevel.Impersonation;

并没有使我的情况不同。

但是,使用这种结合的工作:

      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="Windows" />
        <message clientCredentialType="UserName" />
      </security>        


Answer 7:

尝试在客户端提供的用户名和密码,如下图所示

client.ClientCredentials.UserName.UserName = @ “域\用户名”; client.ClientCredentials.UserName.Password = “密码”;



Answer 8:

刚刚得到一个开发机器上这个问题(生产工作得很好)。 我修改我在IIS中配置为允许匿名访问,并把我的名字和密码作为凭证。

不是最好的方式,我相信,但它适用于测试目的。



Answer 9:

今天我同样的错误,部署我们的服务调用外部服务,在蔚蓝的临时环境后。 本地服务调用的外部服务没有错误,但在部署之后它没有。

最后,它竟然是,外部服务具有IP的验证。 在Azure的新环境还有另外一个IP,它遭到了拒绝。

所以,如果你得到这个错误调用外部服务

这可能是一个IP限制。



文章来源: WCFTestClient The HTTP request is unauthorized with client authentication scheme 'Anonymous'