Web Service 驗證方式<一>SoapHeader驗證
服務端代碼:
注意第7行,需要加[SoapHeader("authHeader")] 特性。
1 public class GetDataList : System.Web.Services.WebService
2 {
3 public AuthHeader authHeader;
4
5
6 [WebMethod]
7 [SoapHeader("authHeader")]
8 public string GetBookList()
9 {
10 string xmlStr = string.Empty;
11 try
12 {
13
14 if (authHeader == null)
15 {
16 XmlDocument xmlDoc = new XmlDocument();
17 XmlDeclaration 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);
23 xmlChild.Attributes.Append(xmlAtt);
24 xmlChild.InnerText = "AuthHeader對象不存在";
25 xmlEle.AppendChild(xmlChild);
26 xmlDoc.AppendChild(xmlEle);
27
28 xmlStr = xmlDoc.InnerXml;
29
30 return xmlStr;
31 }
32 if (!authHeader.Verify())