This article is for you to share the ASP.net page to invoke the SOAP header for validation of the Web services operation steps for your reference, the details are as follows
The first step: the class used for soap validation must derive from the SoapHeader class, and the public properties in the class will appear in the auto-generated XML node, that is:
<soap:Header>
<usersoapheader xmlns= "http://tempuri.org/" >
<username>string</ username>
<Pwd>string</Pwd>
</UserSoapHeader>
</soap:Header>
Public Class Usersoapheader:soapheader
{
private string _username;
private string _pwd;
The properties of public will automatically generate the XML node public
string UserName
{get {return
_username;}
set {_username = value;}
}
public string Pwd
{get
{return _pwd;}
set {_pwd = value;}
}
}
Step Two:
in the WebServices service class, add a public property (must be public), type from Usersoapheader
///<summary>///WebService Summary description///</summary> [WebService (Namespace = "http://tempuri.org/")] [webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1)] public class WebService:
System.Web.Services.WebService {//This property will be the name in the Soapheaderattribute of the Validation property/method Consistent with this variable public usersoapheader userheader;
Public WebService () {//If you are using a design component, uncomment the following line//initializecomponent ();
[WebMethod] [SoapHeader ("Userheader")]//here is important, the name to be consistent with the defined validation property name! When the public string HelloWorld () {//is entered into this method, Userheader will automatically have a value of if (Userheader!= null) {return "' is RetVal
: "+ userheader.username;
Return ' check not successed '; }
}
Step three: Call on the client:
1. Add Web References
2. Instantiation Service class
3. Instantiating the SOAP header (a property that is automatically generated for validation at the client; usersoapheader; the name of the property is: Usersoapheadervalue); The Auto-generated property generation rule is: Validate type name +value;
4. Invoke the method provided by the service.
WebService s = new WebService ();
Usersoapheader a = new Usersoapheader ();
A.username = "admin";
A.PWD = "ZZ";
S.usersoapheadervalue = A; This property is automatically generated
Response.Write (S.helloworld ());//This is Retval:admin
Very simple, I hope everyone can grasp the asp.net in the SoapHeader for verification steps, thank you for your reading.