I have to sent the XML document as an parameter to request an WebRequest from the Service using the Post method.
Can anyone help be about how 开发者_如何转开发to sent the XML document as an parameter, or how to get the whole document in the string to pass as in as Document.
If you want to POST your Xml data using a named form parameter you need to do something like this:
HttpWebRequest request = HttpWebRequest.Create("http://yourdomain.com/whatever") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
Encoding e = Encoding.GetEncoding("iso-8859-1");
XmlDocument doc = new XmlDocument();
doc.LoadXml("<foo><bar>baz</bar></foo>");
string rawXml = doc.OuterXml;
// you need to encode your Xml before you assign it to your parameter
// the POST parameter name is myxmldata
string requestText = string.Format("myxmldata={0}", HttpUtility.UrlEncode(rawXml, e));
Stream requestStream = request.GetRequestStream();
StreamWriter requestWriter = new StreamWriter(requestStream, e);
requestWriter.Write(requestText);
requestWriter.Close();
Read this article Which is explained about the XML document and web service Passing XML document as an parameter to Web services
[WebMethod]
public System.Xml.XmlDocument SampelXmlMethod( System.Xml.XmlDocument xmldoc)
string xmldata = "<xform>" +
"<instance>" +
"<FirstName>Andrew</FirstName>" +
"<LastName>Fuller</LastName>" +
"<BirthDate>2/19/1952</BirthDate>" +
"</instance>" +
"</xform>";
//Load xmldata into XmlDocument Object
System.Xml.XmlDocument SendingXmlDoc = new System.Xml.XmlDocument();
SendingXmlDoc.LoadXml(xmldata);
//Call web service and get xmldocument back
System.Xml.XmlDocument ReceivingXmlDoc = new System.Xml.XmlDocument();
XmlService ser = new XmlService(); //Your web srevice..
ReceivingXmlDoc = ser.SampelXmlMethod(SendingXmlDoc);
精彩评论