Webservice SoapHeaders

How to use a soapheader in webservices:

Server:

 //Webservice
class Service1 : System.Web.Services.WebService
{

public POCHeader Header;

[WebMethod, SoapHeader(“Header”)]
public string WebMethod1()
{
string a = Header.A;
string b = Header.B;
}
}

//SoapHeader Class
[Serializable]
public class POCHeader : SoapHeader
{
public POCHeader(){}

public string A;
public string B;
}

Client:

class Caller
{
private Service1 _webservice;
      

Caller()
{
POCHeader h = new POCHeader();
h.A = “a”;
h.B = “b”;
 

 _webservice = new Service1();
_webservice.UseDefaultCredentials = true;
_webservice.POCHeaderValue = h;

_webservice.WebMethod1();
}
}

Advertisements

%d bloggers like this: