44

I am trying to access my WCF service on a server from my client console application for testing. I am getting the following error:

The caller was not authenticated by the service

I am using 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

Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231

10 Answers10

26

If you use basicHttpBinding, configure the endpoint security to "None" and transport clientCredintialType to "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

Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231
  • @KhumeshKumawat You can create and validate your own answer if you want or simply validate one of the existing (even if it is not exactly the one you chose). Your question has more than 60'000 views so it is an important one. It deserves an "official" an answer. – Askolein Apr 02 '14 at 09:51
24

I got it.

If you want to use wshttpbinding, u need to add windows credentials as below.

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

thanks

Earlz
  • 62,085
  • 98
  • 303
  • 499
  • 4
    And you may need the Domain too (.ClientCredentials.Windows.ClientCredential.Domain) – Retne Oct 06 '09 at 12:10
  • I have strange situation. From one machine i can reach service without explicit ClientCredential.Domain and from another it did not work without Domain – Max Kilovatiy Dec 04 '12 at 16:16
4

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.

Ta01
  • 31,040
  • 13
  • 70
  • 99
2

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.

Nick Giles
  • 562
  • 1
  • 6
  • 15
kishore
  • 21
  • 2
1

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.

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);
Brian
  • 3,653
  • 1
  • 22
  • 33
1

I was able to resolve the shared issue by following below steps:

  1. Go to IIS-->Sites-->Your Site-->
  2. Features View Pane-->Authentication
  3. Set Anonymous Authentication to Disabled
  4. Set Windows Authentication to Enabled

enter image description here

Ajay Shankar
  • 385
  • 3
  • 3
0

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:

<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";
farhang67
  • 759
  • 2
  • 14
  • 27
0

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.

yiannis
  • 440
  • 1
  • 6
  • 19
0

I also had the same problem in wsHtppBinding. And I just had to add security mode pointing to none, that solved my problem and no need to switch to basicHttpBinding. Check Here and check how to disable WCF security. Check the below config change for reference:

<wsHttpBinding>
    <binding name="soapBinding">
        <security mode="None">
            <transport clientCredentialType="None" />
            <message establishSecurityContext="false" />
        </security>
    </binding>
</wsHttpBinding>
Nani
  • 1,148
  • 3
  • 20
  • 35
-2

Why can't you just remove the security setting altogether for wsHttpBinding ("none" instead of "message" or "transport")?

AndiDog
  • 68,631
  • 21
  • 159
  • 205
Can Bilgin
  • 13
  • 1
  • 12
    When someone is having a problem with their security, its not very constructive to answer them with the question "why do you have to use security?" This is a legitimate problem and assuming their application calls for a secure configuration, they need an answer, not an asinine question. – John Ingle Dec 09 '12 at 14:18
  • I disagree - when you're starting with any technology in this area and using sample projects, it's very easy to end up with a whole lot of security stuff enabled by default which you didn't necessarily ask for. – Andy May 12 '14 at 16:49