How to add a custom HTTP header to every WCF call?

后端 未结 13 2294
不知归路
不知归路 2020-11-22 05:33

I have a WCF service that is hosted in a Windows Service. Clients that using this service must pass an identifier every time they\'re calling service methods (because that i

相关标签:
13条回答
  • 2020-11-22 06:35

    This is similar to NimsDotNet answer but shows how to do it programmatically.

    Simply add the header to the binding

    var cl = new MyServiceClient();
    
    var eab = new EndpointAddressBuilder(cl.Endpoint.Address);
    
    eab.Headers.Add( 
          AddressHeader.CreateAddressHeader("ClientIdentification",  // Header Name
                                             string.Empty,           // Namespace
                                             "JabberwockyClient"));  // Header Value
    
    cl.Endpoint.Address = eab.ToEndpointAddress();
    
    0 讨论(0)
提交回复
热议问题