0

I'm trying to convert this binding to a custom binding:

<wsHttpBinding>
  <binding name="ICB">
    <security mode="TransportWithMessageCredential">
      <transport clientCredentialType="Certificate" proxyCredentialType="None"></transport>
      <message    clientCredentialType="UserName"
                  negotiateServiceCredential="false"
                  establishSecurityContext="false" />
    </security>
  </binding>
</wsHttpBinding>

.. and this behavior..

<serviceBehaviors>
  <behavior name="SCB">
    <serviceCredentials>
      <serviceCertificate     findValue="a0 1e dd 76 89 78 a2 67 e3 7d c7 e5 55 5a ec 34 b7 ed 81 f6"
                              storeLocation="LocalMachine"
                              storeName="TrustedPeople"
                              x509FindType="FindByThumbprint" />
      <userNameAuthentication
          userNamePasswordValidationMode="Custom"
          customUserNamePasswordValidatorType="WcfTesting.UsernameValidator, WcfTesting" />
      <clientCertificate>
        <authentication certificateValidationMode="None" revocationMode="NoCheck" />
      </clientCertificate>
    </serviceCredentials> 
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
  </behavior>
</serviceBehaviors>

This works as long as the client has establishSecurityContext=true, how do I change it to false?

class Program
{
    static void Main(string[] args)
    {
        var c = new CustomBinding();
        c.Elements.Add(new TransactionFlowBindingElement());    
        //MessageSecurityVersion version = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
        var sec = // SecurityBindingElement.CreateUserNameOverTransportBindingElement();
            SecurityBindingElement.CreateSecureConversationBindingElement(
                SecurityBindingElement.CreateUserNameOverTransportBindingElement());

        c.Elements.Add(sec);
        c.Elements.Add(new TextMessageEncodingBindingElement()); // {MessageVersion = MessageVersion.Soap11});
        c.Elements.Add(new HttpsTransportBindingElement()); // { RequireClientCertificate = true });

        ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

        using (var host = new System.ServiceModel.ServiceHost( typeof (TestService) ))
        {
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(TestService), c, "https://localhost:1235");
            host.Credentials.ServiceCertificate.SetCertificate(
                StoreLocation.LocalMachine,
                StoreName.TrustedPeople,
                X509FindType.FindByThumbprint,
                "a01edd768978a267e37dc7e5555aec34b7ed81f6");
            host.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
            host.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator  = new UsernameValidator();
            host.Open();
            Console.WriteLine("SERVICE STARTED>>");
            Console.ReadLine();
        }
    }
}

I used the results of WCFBindingBox as the basis of my conversion, here is the results:

<!-- generated via Yaron Naveh's http://webservices20.blogspot.com/ -->

<customBinding>
  <binding name="NewBinding0">
    <transactionFlow />
    <security authenticationMode="UserNameOverTransport" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
    <textMessageEncoding />
    <httpsTransport />
  </binding>
</customBinding>

<!-- generated via Yaron Naveh's http://webservices20.blogspot.com/ -->
Dog Ears
  • 9,637
  • 5
  • 37
  • 54

1 Answers1

1

You can automatically convert to a custom binding via the binding box. Generally speaking if establishSecurityContext is false you do not need CreateSecureConversationBindingElement. Instead directly use CreateUserNameOverTransportBindingElement.

Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158
  • my attempt at conversion to code is based on the results from your converter. I'll try your suggestion. cheers. – Dog Ears Aug 14 '13 at 14:42
  • OK, I must have pasted the wrong binding into your converter initially, as it works by simply using the `SecurityBindingElement.CreateUserNameOverTransportBindingElement();` thanks. – Dog Ears Aug 14 '13 at 14:52
  • Now I need to add a signed timestamp element to the message.. (see here: http://stackoverflow.com/questions/3785536/ ) – Dog Ears Aug 14 '13 at 14:56