SOAP Header (credentials) for cosuming web service
Its the optional part of SOAP Message. Instead including meta data (Credentials) in your web signature you can use SOAP header to consume web service.
// SOAP Header class
public class HelloHeader : SoapHeader
{
public string Username;
public string Password;
}
public HelloHeader myHeader;
[WebMethod]
[SoapHeader("myHeader")]
public string HelloWorld()
{
if (myHeader == null)
{
return "Hello World";
}
else
{
return "Hello " + myHeader.Username + ". " +
"
Your password is: " + myHeader.Password;
}
}
// Consuming this web service
localhost.HelloHeader objHEader = new WindowsApplication1.localhost.HelloHeader();
localhost.HelloSoapHeader objService = new WindowsApplication1.localhost.HelloSoapHeader();
objHEader.Username = "milind";
objHEader.Password = "mahajan";
objService.HelloHeaderValue = objHEader;
MessageBox.Show( objService.HelloWorld());
// SOAP Header class
public class HelloHeader : SoapHeader
{
public string Username;
public string Password;
}
public HelloHeader myHeader;
[WebMethod]
[SoapHeader("myHeader")]
public string HelloWorld()
{
if (myHeader == null)
{
return "Hello World";
}
else
{
return "Hello " + myHeader.Username + ". " +
"
Your password is: " + myHeader.Password;
}
}
// Consuming this web service
localhost.HelloHeader objHEader = new WindowsApplication1.localhost.HelloHeader();
localhost.HelloSoapHeader objService = new WindowsApplication1.localhost.HelloSoapHeader();
objHEader.Username = "milind";
objHEader.Password = "mahajan";
objService.HelloHeaderValue = objHEader;
MessageBox.Show( objService.HelloWorld());
Good Day!
ReplyDeleteYou know how to consume this webservice for example with jquery ajax passing the Soap Header?