Adding custom header to generated SOAP proxy

3.8k views Asked by At

I have generated a proxy class from a wsdl file (C# VS 2008) The webservice expects an element within the soap header. When I try to add this element using proxy.RequestSoapContext.Envelope.Header I receive a null error. The envelope is null. How do I am a custom element to the header ?

Many thanks.

1

There are 1 answers

7
Amar Palsapure On BEST ANSWER

Try this

EndpointAddressBuilder endpointAddressBuilder = 
          new EndpointAddressBuilder(proxy.Endpoint.Address);
foreach (var item in headers) //headers is a Dictionary<string, string>
     endpointAddressBuilder.Headers.Add(
          AddressHeader.CreateAddressHeader(item.Key, "nameSpace", item.Value));
proxy.Endpoint.Address = endpointAddressBuilder.ToEndpointAddress();

Hope this works for you.