CREATE A WEB
SERVICE
public
class
AuthenticationHeader
: SoapHeader
{
public
string
Username;
public
string
Password;
}
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo =
WsiProfiles.BasicProfile1_1)]
public
class
MyWebService
: System.Web.Services.WebService
{
public
AuthenticationHeader
AuthHeader;
[WebMethod(), SoapHeader("AuthHeader")]
public
string
GetMessage()
{
if
(AuthHeader.Username == "user"
&& AuthHeader.Password == "password")
return
"This is the secret message!!!";
else
return
"YOU ARE NOT AUTHORIZED TO SEE THIS
MESSAGE!";
}
}
CONSUME THE WEB SERVICE
MyWebService
proxy = newMyWebService();
AuthenticationHeader
authInfo = newAuthenticationHeader();
authInfo.Username = "user";
authInfo.Password = "password";
proxy.AuthHeader = authInfo;
string
result = proxy.GetMessage();
Response.Write(result);