Search code examples
c#wcfws-securitywshttpbinding

Add Header to WCF RequestSecurityToken Message


I'm attempting to set up a client (Web Application) and service (WCF Service) that will communicate using a WSHttpBinding. It appears that in order to use this binding the client sends preliminary messages to set up the channel.

Between the client and the service exists a service bus which is routing on a custom header. The message, when using BasicHttpBinding security, routes without issue.

My question is: Is there any way to add the same custom header to the preliminary RequestSecurityToken message?

Thank you in advance.


Solution

  • This has been resolved.

    Unfortunately, according to the MSDN documentation, a service using WCF transport security cannot go through a router, nor should either, service nor client, be located on the internet (https://msdn.microsoft.com/en-us/library/ff648863.aspx#TransportSecurity).

    We wanted to violate both 'principles'.

    So in order to cut down the messages, from five calls and responses to one, we switched to Message Security and turned off EstablishSecurityContext and NegotiateServiceCredential. - This had to be done on both the Service and Client configuration settings.

    In addition to this, a noteworthy tip may be that, in order to point the service to our service bus, we changed theClientViaBehavior of the service on the Client Side.

    Turn off EstablishContext and NegotiateServiceCredential:

    WSHttpBinding binding = new WSHttpBinding();
    
    binding.Security.Mode = SecurityMode.Message;
    binding.Security.Message.EstablishSecurityContext = false;
    binding.Security.Message.NegotiateServiceCredential = false;
    

    Point client to Service Bus:

    serviceClient.Endpoint.EndpointBehaviors.Add(new ClientViaBehavior(new Uri("http://url/WCFService/ServiceName.svc")));