-----打开网址:http://localhost:63596/WebService2.asmx?op=UpdatePerson:
请求部分如下:
POST /WebService2.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/UpdatePerson"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<UpdatePerson xmlns="http://tempuri.org/">
<Person1>
<Id>int</Id>
<name>string</name>
<age>int</age>
</Person1>
</UpdatePerson>
</soap:Body>
</soap:Envelope>
---------先把实体类序列还成xml字符串,然后变成XmlDocument对象,再取对象合适的部分。
var ss = "";
using (StringWriter sw = new StringWriter())
{
var p = new Person1 { Id = 1, name = "HelenZhouZhou", age = 20 };
Type t = p.GetType();
XmlSerializer serializer = new XmlSerializer(p.GetType());
serializer.Serialize(sw, p);
sw.Close();
ss = sw.ToString();
}
XmlDocument aa = new XmlDocument();
aa.LoadXml(ss);
XmlNode Person1 = aa.SelectSingleNode("Person1");
ss = Person1.InnerXml;
------在soap组合参数时,soapMethod是方法节点对象,soapPar是参数节点对象(可以是对象名称,也可以是普通参数名称),Pars[k]是参数值
XmlElement soapPar = doc.CreateElement(k);
soapPar.InnerXml = Pars[k].ToString();
soapMethod.AppendChild(soapPar);
--------最后能组合成<soap:Envelope 。。。。。。。就可以了。