首先,要建立一個繼承自System.Web.Services.Protocols.SoapHeader的RequestSOAPHeader類,在其中新增UserName和Password兩個屬性,程式碼如下: public class RequestSOAPHeader : System.Web.Services.Protocols. SoapHeader{ public string user { get; set; } public string password { get; set; }} 生成的WebService代理類中設定成屬性成員: public partial class ISysNotifyTodoWebServiceService{ public RequestSOAPHeader RequestSOAPHeader { get; set; }} 在訪問的WebService方法上方新增SOAPHeader的宣告: [System.Web.Services.Protocols. SoapDocumentMethodAttribute( "", RequestNamespace="http://webservice.notify.sys/" , ResponseNamespace="http://webservice.notify.sys/" , Use=System.Web.Services.Description.SoapBindingUse .Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle .Wrapped)][ return: System.Xml.Serialization. XmlElementAttribute( "return", Form=System.Xml.Schema.XmlSchemaForm .Unqualified)][ SoapHeader( "RequestSOAPHeader")]public notifyTodoAppResult setTodoDone([System.Xml.Serialization.XmlElementAttribute (Form=System.Xml.Schema.XmlSchemaForm .Unqualified)] notifyTodoRemoveContext arg0) { object[] results = this.Invoke( "setTodoDone", new object[] { arg0}); return (( notifyTodoAppResult)(results[0]));}
首先,要建立一個繼承自System.Web.Services.Protocols.SoapHeader的RequestSOAPHeader類,在其中新增UserName和Password兩個屬性,程式碼如下: public class RequestSOAPHeader : System.Web.Services.Protocols. SoapHeader{ public string user { get; set; } public string password { get; set; }} 生成的WebService代理類中設定成屬性成員: public partial class ISysNotifyTodoWebServiceService{ public RequestSOAPHeader RequestSOAPHeader { get; set; }} 在訪問的WebService方法上方新增SOAPHeader的宣告: [System.Web.Services.Protocols. SoapDocumentMethodAttribute( "", RequestNamespace="http://webservice.notify.sys/" , ResponseNamespace="http://webservice.notify.sys/" , Use=System.Web.Services.Description.SoapBindingUse .Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle .Wrapped)][ return: System.Xml.Serialization. XmlElementAttribute( "return", Form=System.Xml.Schema.XmlSchemaForm .Unqualified)][ SoapHeader( "RequestSOAPHeader")]public notifyTodoAppResult setTodoDone([System.Xml.Serialization.XmlElementAttribute (Form=System.Xml.Schema.XmlSchemaForm .Unqualified)] notifyTodoRemoveContext arg0) { object[] results = this.Invoke( "setTodoDone", new object[] { arg0}); return (( notifyTodoAppResult)(results[0]));}