如何发布的.NET SOAP请求?NET、SOAP

2023-09-02 02:08:04 作者:痞笑

我有一个XML文件中的SOAP请求。我要张贴请求在.NET Web服务 如何实现?

解决方案

VAR URI =新的URI(HTTP://本地主机/ SOAP / SOAPSMS.asmx /加); VAR REQ =(HttpWebRequest的)WebRequest.CreateDefault(URI); req.Co​​ntentType =为text / xml;字符集= UTF-8; req.Method =POST; req.Accept =为text / xml; req.Headers.Add(SOAPAction的,的http://localhost/SOAP/SOAPSMS.asmx/add); VAR strSoapMessage = @< XML版本=1.0编码=UTF-8&GT?; <肥皂:信封XMLNS:肥皂=HTTP://schemas.xmlsoap.org/soap/envelope/                的xmlns:XSI =HTTP://www.w3.org/2001/XMLSchema-instance                的xmlns:XSD =HTTP://www.w3.org/2001/XMLSchema'>   <肥皂:身体与GT;<添加的xmlns =HTTP://tempuri.org/'>< A> 23℃; / A>< B> 5℃; / B>< / SOAP:身体与GT; < /肥皂:信封>中; 使用(VAR流=新的StreamWriter(req.GetRequestStream(),Encoding.UTF8))     stream.Write(strSoapMessage);

I have the SOAP request in an XML file. I want to post the request to the web service in .net How to implement?

解决方案 .Net之SoapCore简单使用

var uri = new Uri("http://localhost/SOAP/SOAPSMS.asmx/add");

var req = (HttpWebRequest) WebRequest.CreateDefault(uri); 
req.ContentType = "text/xml; charset=utf-8"; 
req.Method = "POST"; 
req.Accept = "text/xml"; 
req.Headers.Add("SOAPAction", "http://localhost/SOAP/SOAPSMS.asmx/add"); 

var strSoapMessage = @"<?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><add xmlns='http://tempuri.org/'><a>23</a><b>5</b></soap:Body>
</soap:Envelope>"; 

using (var stream = new StreamWriter(req.GetRequestStream(), Encoding.UTF8)) 
    stream.Write(strSoapMessage);