How to post SOAP Request from .NET?

前端 未结 7 2000
暖寄归人
暖寄归人 2020-12-08 02:28

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

相关标签:
7条回答
  • 2020-12-08 03:25
    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); 
    
    0 讨论(0)
提交回复
热议问题