WCFTestClient The HTTP request is unauthorized with client authentication scheme 'Anonymous'

前端 未结 9 1450
囚心锁ツ
囚心锁ツ 2020-12-05 01:34

I\'ve created one WCF service and deployed it on Server. When I browse this service it gives me positive response with ?wsdl URL. Now I\'m trying to test the service through

相关标签:
9条回答
  • 2020-12-05 02:09

    I had a similar problem and tried everything suggested above. Then I tried changing the clientCreditialType to Basic and everything worked fine.

    <basicHttpBinding>
        <binding name="BINDINGNAMEGOESHERE" >
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic"></transport>
          </security>
        </binding>
      </basicHttpBinding>
    
    0 讨论(0)
  • 2020-12-05 02:13

    Here's what I had to do to get this working. This means:

    1. Custom UserNamePasswordValidator (no need for a Windows account, SQLServer or ActiveDirectory -- your UserNamePasswordValidator could have username & password hardcoded, or read it from a text file, MySQL or whatever).
    2. https
    3. IIS7
    4. .net 4.0

    My site is managed through DotNetPanel. It has 3 security options for virtual directories:

    1. Allow Anonymous Access
    2. Enable Basic Authentication
    3. Enable Integrated Windows Authentication

    Only "Allow Anonymous Access" is needed (although, that, by itself wasn't enough).

    Setting

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

    Didn't make a difference in my case.

    However, using this binding worked:

          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="Windows" />
            <message clientCredentialType="UserName" />
          </security>        
    
    0 讨论(0)
  • 2020-12-05 02:14

    I didn't have control over the security configuration for the service I was calling into, but got the same error. I was able to fix my client as follows.

    1. In the config, set up the security mode:

      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
      
    2. In the code, set the proxy class to allow impersonation (I added a reference to a service called customer):

      Customer_PortClient proxy = new Customer_PortClient();
      proxy.ClientCredentials.Windows.AllowedImpersonationLevel =    
               System.Security.Principal.TokenImpersonationLevel.Impersonation;
      
    0 讨论(0)
提交回复
热议问题