Web Service authentication method <1> SoapHeader Verification
Server code:
Note that the [SoapHeader ("authHeader")] feature must be added to the 7th rows.
1 public classGetDataList: System. Web. Services. WebService
2{
3 publicAuthHeader authHeader;
4
5
6[WebMethod]
7 [SoapHeader ("authHeader")]
8 public stringGetBookList ()
9{
10 string xmlStr = string. Empty;
11 try
12{
13
14 if (authHeader = null)
15{
16 XmlDocument xmlDoc = newXmlDocument ();
17XmlDeclaration xmlDec;
18 xmlDec = xmlDoc. CreateXmlDeclaration ("1.0", "UTF-8", null);
19 XmlElement xmlEle = xmlDoc. CreateElement (null, "soapheader", null);
20 XmlAttribute xmlAtt = xmlDoc. CreateAttribute ("allowView");
21 xmlAtt. InnerText = "true";
22 XmlElement xmlChild = xmlDoc. CreateElement (null, "status", null);
23XmlChild. Attributes. Append (xmlAtt );
24 xmlChild. InnerText = "The AuthHeader object does not exist";
25XmlEle. AppendChild (xmlChild );
26XmlDoc. AppendChild (xmlEle );
27
28 xmlStr =XmlDoc. InnerXml;
29
30 returnXmlStr;
31}
32 if (!AuthHeader. Verify ())