Web Service 三种身份验证方式
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())补充:软件开发 , C# ,