使用HttpClient从SOAP post请求中检索响应字段

时间:2018-06-08 07:10:45

标签: c# web-services soap xamarin.forms httpclient

我对SOAP请求相当新。我已经完成了一个使用HTTPClient工作的POST请求,但我无法弄清楚如何检索响应字段 “1F833967EB46324480005B68BCAAAF8900”

我的代码:

 public async Task<string> CreateSoapEnvelop(string userId)
        {
            string soapString = @"<?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>
                 <Logon_With_String xmlns=""http://www.syspro.com/ns/utilities/"">
                  <OperatorCode>" + Settings.UserId + @"</OperatorCode>
                  <OperatorPassword></OperatorPassword>
                  <CompanyId>TIH</CompanyId>
                  <CompanyPassword></CompanyPassword>
                  <LanguageCode>AUTO</LanguageCode>
                  <LogLevel>ldNoDebug</LogLevel>
                  <EncoreInstance>EncoreInstance_0</EncoreInstance>
                  <XmlIn></XmlIn>
                  </Logon_With_String>
                </soap:Body>
            </soap:Envelope>";

            HttpResponseMessage response = await PostXmlRequest("http://url/sysprowebservices/utilities.asmx", soapString);
            string content = await response.Content.ReadAsStringAsync();

            return content;

        }

        public static async Task<HttpResponseMessage> PostXmlRequest(string baseUrl, string xmlString)
        {
            using (var httpClient = new HttpClient())
            {
                var httpContent = new StringContent(xmlString, Encoding.UTF8, "text/xml");
                httpContent.Headers.Add("SOAPAction", "http://url/utilities/Logon_With_String");

                return await httpClient.PostAsync(baseUrl, httpContent);
            }
        }

回复

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <Logon_With_StringResponse xmlns="http://url/">
            <Logon_With_StringResult>1F833967EB46324480005B68BCAAAF8900  </Logon_With_StringResult>
        </Logon_With_StringResponse>
    </soap:Body>
</soap:Envelope>

因此,从响应中我需要检索响应值,因为它将在我的应用程序中用于其他请求。任何帮助将不胜感激,谢谢

0 个答案:

没有答案
相关问题