如何从 .NET 发布 SOAP 请求? [英] How to post SOAP Request from .NET?

查看:27
本文介绍了如何从 .NET 发布 SOAP 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 XML 文件中有 SOAP 请求.我想将请求发布到 .net 中的 Web 服务如何实施?

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

推荐答案

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); 

这篇关于如何从 .NET 发布 SOAP 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆