生成代理类后,假设代理类为Reference.cs,打开文件,手工添加和修改以下代码:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/", IsNullable=false)]
    public partial class MyHeader : System.Web.Services.Protocols.SoapHeader {
        
        private string tokenField;
        
        private System.Xml.XmlAttribute[] anyAttrField;
        
        /// <res/>
        public string token {
            get {
                return this.tokenField;
            }
            set {
                this.tokenField = value;
            }
        }
        
        /// <res/>
        [System.Xml.Serialization.XmlAnyAttributeAttribute()]
        public System.Xml.XmlAttribute[] AnyAttr {
            get {
                return this.anyAttrField;
            }
            set {
                this.anyAttrField = value;
            }
        }
    }   
   
   
    /// <res/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.4927")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Web.Services.WebServiceBindingAttribute(Name="AccountServiceSoapBinding", Namespace="http://api.tg.soso.com/advertise/accountservice/v1")]
    public partial class AccountService : System.Web.Services.Protocols.SoapHttpClientProtocol {
        private MyHeader _token;
        
        public MyHeader token
        {
         get
         {
         return _token;
         }
         set
         {
         _token = value;
         }
        
        } 
然后在每个你要调用的webmethod前添加这个特性:
[System.Web.Services.Protocols.SoapHeaderAttribute("token")]比如getAdvertiserInfo()这个方法,修改后就变成:        [System.Web.Services.Protocols.SoapHeaderAttribute("token")]
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://api.tg.soso.com/advertise/AccountService/V1/getAdvertiserInfo", RequestElementName="getAdvertiserInfoRequest", RequestNamespace="http://api.tg.soso.com/advertise/accountservice/v1", ResponseNamespace="http://api.tg.soso.com/advertise/accountservice/v1", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        [return: System.Xml.Serialization.XmlElementAttribute("advertiser", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public AdvertiserType getAdvertiserInfo() {
            object[] results = this.Invoke("getAdvertiserInfo", new object[0]);
            return ((AdvertiserType)(results[0]));
        }调用:                com.qq.tg.api_sandbox.AccountService client = new WindowsFormsApplication1.com.qq.tg.api_sandbox.AccountService();
                client.token = new WindowsFormsApplication1.com.qq.tg.api_sandbox.MyHeader();
                client.token.token = "d573b032-507f-4f07-88da-7a4019d36252";
var t = client.getAdvertiserInfo();在vs2008上调试通过,以上返回值,t.advertiserName = "王玉(前台测试勿动)";