公用类定义验证信息类: namespace CCWCommon { public class ClientKey:SoapHeader { private string _userName; public string UserName { get { return _userName; } set { _userName = value; } } private string _password; public string PassWord { get { return _password; } set { _password = value; } } public ClientKey() { } } } WebService加验证方法: private CCWCommon.ClientKey _clientKey = new CCWCommon.ClientKey(); public CCWCommon.ClientKey ClientKey { get { return _clientKey; } set { _clientKey = value; } } [WebMethod] [SoapHeader("ClientKey")] public byte[] TestClientKey() { string tt = ""; if (_clientKey.UserName == null) { tt= "111"; } else { tt= _clientKey.UserName; } byte[] bresult = CCWCommon.Serialization.ToSerialization(tt); return bresult; } 客户端程序方法: Type t = asm.GetType(CCWCommon.Common.MainWebNameSpace + "." + className); //Soap头开始 FieldInfo client = t.GetField("ClientKeyValue"); //获取客户端验证对象 Type typeClient = asm.GetType(CCWCommon.Common.MainWebNameSpace + ".ClientKey"); FieldInfo userName = typeClient.GetField("UserName"); FieldInfo passWord = typeClient.GetField("PassWord"); //为验证对象赋值 object clientkey = Activator.CreateInstance(typeClient); userName.SetValue(clientkey, CCWSubDLL.Common.RegSub.UserInfo.UserName); passWord.SetValue(clientkey, CCWSubDLL.Common.RegSub.UserInfo.PassWord); //Soap头结束 //实例类型对象 object o = Activator.CreateInstance(t); //设置Soap头 client.SetValue(o, clientkey); //获取方法 MethodInfo method = t.GetMethod(methodName);