Part 2: Adding Soap headers to the client
Adding headers to the client is even easer than adding them to the server, which I showed in part 1: Adding Soap headers to a webservice. As you can see the headers are also added to the WSDL and the wsdl.exe tool or the VS webreference wizard will add them to the proxy.
<wsdl:binding name="Service1Soap" type="tns:Service1Soap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="HelloWorld"> <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> <wsdl:input> <soap:body use="literal" /> <soap:header message="tns:HelloWorlduserNamePasswordHeader" part="userNamePasswordHeader" use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding>
If that doesn't work or the headers are not in the wsdl, you can add the property manually and associate the header with the method using the soapheader attribute. This works exactly the same as for the server.
WebClient.zip (8.59 KB)
Update 23 Oct. 2007: Replaced the zip with a version which compiles.