Возврат данных узла XML с помощью C#
У меня есть следующие XML-результаты, которые генерируются при запуске SOAP-запроса к веб-сервису.
<?xml version="1.0" encoding="utf-8" ?> - <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> - <SOAP-ENV:Body> - <idc:service xmlns:idc="http://www.stellent.com/IdcService/" IdcService="SEARCH_WORKFLOWS"> - <idc:document dUser="user"> <idc:field name="SearchAuthor" /> <idc:field name="SearchCID">arf</idc:field> <idc:field name="SearchAssn" /> - <idc:resultset name="WfDocuments"> - <idc:row dDocName="ARF16-0711" dID="596213" dDocType="JPS_QMARF" dDocTitle="ARF16-0711 AMYWSA3377 Prop Lbl Prod PV Mat LStatn" dDocAuthor="author" dRevClassID="283640" dRevisionID="1" dRevLabel="A0" dIsCheckedOut="0" dCheckoutUser="" dSecurityGroup="Submitted_Forms" dCreateDate="8/23/16 3:10 PM" dInDate="8/23/16 3:10 PM" dOutDate="" dStatus="REVIEW" dReleaseState="E" dFlag1="" dWebExtension="hcsp" dProcessingState="Y" dMessage="" dDocAccount="" dReleaseDate="" dRendition1="" dRendition2="" dIndexerState="" dPublishType="" dPublishState=""> </idc:row> </idc:resultset> </idc:document> </idc:service> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Полная строка вызова SOAP https://auhjpsv01/stellent/idcplg?=SEARCH_WORKFLOWS&амп IdcService;SearchAssn=&ампер;SearchCID=АРФ&амп;SearchAuthor=&ампер;IsSoap=1[^]
Я хочу разобрать данные узла dDocName (ARF16-0711) и данные узла dCreateDate (8/23/16 3:10 вечера) в текстовое поле, но продолжаю получать следующую ошибку с моим кодом.
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:body> <soap-env:fault> <faultcode>Client</faultcode> <faultstring>The Soap request is invalid. The service node '(null)' is invalid.</faultstring> </soap-env:fault> </soap-env:body> </soap-env:envelope>
Что я уже пробовал:
Вот мой код.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; namespace SOAP_reference { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { setupWebServiceSOAPCall(); } public void setupWebServiceSOAPCall() { var _url = "https://auhjpsv01/stellent/idcplg?IdcService=SEARCH_WORKFLOWS&SearchAssn=&SearchCID=arf&SearchAuthor=&IsSoap=1"; var _action = "https://auhjpsv01/stellent/idcplg?IdcService=SEARCH_WORKFLOWS&SearchAssn=&SearchCID=arf&SearchAuthor=&IsSoap=1"; XmlDocument soapEnvelopeXml = CreateSOAPXMLEnvelope(); HttpWebRequest webRequest = CreateSOAPWebRequest(_url, _action); InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest); // begin async call to web request. IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null); // suspend this thread until call is complete. You might want to // do something usefull here like update your UI. asyncResult.AsyncWaitHandle.WaitOne(); // get the response from the completed web request. string soapResult; using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) { using (StreamReader rd = new StreamReader(webResponse.GetResponseStream())) { soapResult = rd.ReadToEnd(); } Console.Write(soapResult); textBox1.Text = soapResult; } } private static HttpWebRequest CreateSOAPWebRequest(string url, string action) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Headers.Add("SOAPAction", action); request.ContentType = "text/xml;charset=\"utf-8\""; request.Accept = "text/xml"; request.Method = "POST"; return request; } private static XmlDocument CreateSOAPXMLEnvelope() { XmlDocument envelop = new XmlDocument(); envelop.LoadXml(@"<idc:document duser="" gittlera="" xmlns:idc="#unknown"><idc:field name="" searchauthor="" /><idc:field name="" searchcid="">arf</idc:field><idc:field name="" searchassn="" /><idc:resultset name="" wfdocuments=""></idc:resultset></idc:document><soap-env:body xmlns:soap-env="#unknown"></soap-env:body>"); return envelop; } private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest) { using (Stream stream = webRequest.GetRequestStream()) { soapEnvelopeXml.Save(stream); } } } }