Postメソッドを使用してWebRequestをWebサービスに要求するパラメータとしてXMLドキュメントを送信する必要があります。C#のWebサービスへのパラメータとしてのXMLドキュメントの受け渡し
XMLドキュメントをパラメータとして送信する方法や、文字列内のドキュメント全体をDocumentとして渡す方法についてお手伝いできます。
Postメソッドを使用してWebRequestをWebサービスに要求するパラメータとしてXMLドキュメントを送信する必要があります。C#のWebサービスへのパラメータとしてのXMLドキュメントの受け渡し
XMLドキュメントをパラメータとして送信する方法や、文字列内のドキュメント全体をDocumentとして渡す方法についてお手伝いできます。
について説明されているこの記事を読む:
を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();
Filburtに感謝します。しかし、XMLDocumentを使用してXMLDocumentを文字列に変換する方法を指定できますか? –
@Bhavik EvgKと同様に、XmlDocument.OuterXmlプロパティでXml文字列を取得できることを提案しました。 – Filburt
残念ですが、そのようなプロパティXmlDocument.OuterXmlはなく、代わりにXmlNode.OuterXmlです。 –
という名前のフォームパラメータを使用してXMLデータを投稿したい場合は、このような何かする必要があるXMLドキュメントとWebサービス 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);
申し訳ありませんが、POSTメソッドを使ってこれを取得する必要があります。これを関数の引数として渡すことはできません。 –
タグ 'web-services'はここで少し誤解を招いています。あなたはWebServiceを消費するのではなく、FormデータのようなXmlデータをポストします。 – Filburt
XmlDocument.OuterXml(string型)を送信しようとしましたか? – EvgK
このOutbreak機能はOuterXMLとは何ですか?私はこれはXMLDocumentではなく、XmlNodeのためのものです。 –