Creating a WCF service compatible with PCL

I am trying to create a WCF service I can consume with my PCL application.

The WCF service will be IIS hosted with SSL and custom username/password authentication.

I see that PCL only supports BasicHttpBinding. What is the simplest way to create a WCF service that will work with something like this:

var temp = new MyWebServiceClient();
                temp.ClientCredentials.UserName.UserName = "username";
                temp.ClientCredentials.UserName.Password = "password";
                var result = temp.GetSomething("");

Right now I am trying to use basicHttpBinding with clientCredentialType="Basic" but am having a lot of trouble getting custom auth to work properly. Does anyone have any suggestions?

Thanks much

Answers

  • NicolaLoroNicolaLoro USMember ✭✭

    Hi Julien. I was looking for a reply to my issue, but found your question.
    You need to setup your WCF service with userNameAuthentication, like this:

          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="YourValidator, YourBinaryWhereValidatorIs" />
          </serviceCredentials>
    

    Have a look around, you should find how to create your custom validator. Then on the PCL side, you can do something like this:

                var ServiceendPoint = new EndpointAddress(new Uri(URL));
                var binding = new BasicHttpBinding();
                binding.MaxBufferSize = 2147483647;
                binding.MaxReceivedMessageSize = 2147483647;
                binding.Security.Mode = BasicHttpSecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                YourClient client = new YourClient(binding, ServiceendPoint);
                client.ClientCredentials.UserName.UserName = username;
                client.ClientCredentials.UserName.Password = password;
                var result = await client.DoSomething();
    

    The credentials validation is then automatically made by the WCF service at transport level. So the call to DoSomething will work only if they get validated.

Sign In or Register to comment.