SOAP Headers can play an important role in SOAP messages. Using headers is as easy as creating a custom class that derives from the SoapHeader class, referencing the custom class in the Web Service, and then adding the header to a Web Method by using the SoapHeaderAttribute class. On the consumer/client-side, very little code is required to add a SOAP header into a request. The proxy object will do the majority of the work to add header details into SOAP messages. By using headers you can separate data that is used by the Web Service but not directly related to functionality exposed by a given Web Method.
This sample application shows how to use SOAP headers to create a custom authentication scheme. After a user logs into a service with a user name and password, the Web Service returns a unique authentication token which is then sent by the service consumer as a header in subsequent SOAP messages.
|