Sandeep
Sandeep

Reputation: 357

Can't authenticate using wsHttpBinding with ClientCredentialsType=Username

I am new to WCF and now really lost with this problem... I want my WCF Service to authenticate incoming request using the username and password provided by client.

Relevant parts of Web.Config looks like this:

<endpoint name="wsBinding" 
          address="" 
          binding="wsHttpBinding" 
          contract="ServiceLib.IBooking" 
          bindingConfiguration="myWSSettings"
          />

And...

<bindings>
  <wsHttpBinding>
    <binding name="myWSSettings">
      <security mode="Transport">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>


<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>

      <serviceCredentials>
        <userNameAuthentication
          userNamePasswordValidationMode="Custom"
          customUserNamePasswordValidatorType= "ServiceLib.MyCustomUserNameValidator, ServiceLib" />
      </serviceCredentials>

    </behavior>
  </serviceBehaviors>
</behaviors>

MyCustomUserNameValidator is just a temporary validator which simply throws Exception if username is not equal to password.

Client program (a console app) is doing this:

        BookingClient client = new BookingClient("wsBinding");
        Passenger passenger = new Passenger();

        // ../

        client.ClientCredentials.UserName.UserName = "SomeUserName";
        client.ClientCredentials.UserName.Password = "WrongPassword";

        // ...
        // ...

        // NOTE: Following should throw My SecurityException Since username and
        // Password are not equal
        bool confirmed = client.IsTicketConfirmed(passenger);

This is the error I get:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM,Basic

Would really appreciate any help! I have spent tons of time trying to figure this out but in vain.

Thanks Sandeep

Note:--------

  1. I am using GoDaddy to host my WCF Service. Security mode = "Message" cannot be used there due to partial trust.
  2. SSL certificate is correctly installed.

Upvotes: 2

Views: 2330

Answers (1)

Brice2Paris
Brice2Paris

Reputation: 206

You must change security mode to TransportWithMessageCredential :

        <wsHttpBinding>
            <binding name="SafeServiceConf">
                <security mode="TransportWithMessageCredential">
                    <message clientCredentialType="UserName"/>
                </security>
            </binding>
        </wsHttpBinding>

You will found a good sample here.

Upvotes: 1

Related Questions