1

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.

Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46
user1180360
  • 33
  • 1
  • 4

1 Answers1

1

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.

Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46
  • Thankyou Amar. That worked! It took me a while as my generated proxy was from wsdl.exe rather than svcutil.exe. – user1180360 Feb 02 '12 at 10:53
  • On the off chance I am now getting the error No SOAPAction Header defined. Any thoughts ? I'm new to web services and find it a mine field of objects etc. – user1180360 Feb 02 '12 at 10:54
  • Answered this myself. Switched from WcfBinding to Basic. – user1180360 Feb 02 '12 at 11:07
  • Great to hear that. You can check [this](http://stackoverflow.com/questions/8820105/configure-wcf-service-programatically) post also, might help you. – Amar Palsapure Feb 02 '12 at 11:18
  • Hi Amar. I hope its not inappropriate to ask a question like this. Its just you know the context and it might be easier to answer. I am using client.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign This doesnt fully work as the URI of the signature points to _0 but the message body does not have an ID. I have been pulling my hair out looking for where to specify an ID. Any suggestions would be most welcome. (As an aside I find the MS way of implementing web services the most messy and awkward) Kind regards Tom – user1180360 Feb 07 '12 at 11:18
  • Sorry but never done this. Will check this over the weekend and will try to answer your question. – Amar Palsapure Feb 07 '12 at 11:27
  • Thankyou Amar. You have been a great help. – user1180360 Feb 07 '12 at 11:33