获得soapClient发送的xml字符串

$client SoapClient("some.wsdl", array('trace' => 1));
$result $client->SomeFunction(array('iTopN'=>5));

echo "REQUEST:\n" $client->__getLastRequest() . "\n";




 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C#中发送并处理SOAP格式的XML数据,可以使用System.Net.Http和System.Xml.Linq命名空间中的类和方法。 首先,需要使用System.Net.Http.HttpClient类创建一个HTTP客户端对象,然后使用HttpClient.PostAsync方法发送SOAP消息。在PostAsync方法中,必须指定SOAP消息的内容类型为"text/xml",并将SOAP消息作为字符串传递给HttpContent对象。 以下是一个简单的示例代码: ```csharp using System; using System.Net.Http; using System.Xml.Linq; using System.Text; namespace SoapHttpClient { class Program { static async void SendSoapMessage() { // 构造SOAP消息 XNamespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/"; XNamespace ns = "http://www.example.org/sample"; XElement body = new XElement(ns + "SampleRequest", new XElement(ns + "Parameter", "Value")); XElement envelope = new XElement(soapenv + "Envelope", new XAttribute(XNamespace.Xmlns + "soapenv", soapenv), new XAttribute(XNamespace.Xmlns + "sam", ns), new XElement(soapenv + "Body", body)); string soapMessage = envelope.ToString(); // 创建HTTP客户端对象 HttpClient client = new HttpClient(); // 发送SOAP消息 HttpContent content = new StringContent(soapMessage, Encoding.UTF8, "text/xml"); HttpResponseMessage response = await client.PostAsync("http://example.com/soap-service", content); // 处理响应 if (response.IsSuccessStatusCode) { string responseXml = await response.Content.ReadAsStringAsync(); XDocument responseDoc = XDocument.Parse(responseXml); XElement responseBody = responseDoc.Descendants(ns + "SampleResponse").FirstOrDefault(); if (responseBody != null) { // 处理响应体 } } else { // 处理错误响应 } } static void Main(string[] args) { SendSoapMessage(); Console.ReadKey(); } } } ``` 在这个示例中,我们使用LINQ to XML构造了一个SOAP消息,然后使用HttpClient.PostAsync方法发送SOAP消息。在响应中,我们首先将响应体解析为XML文档,然后使用LINQ to XML查询响应体中的元素。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值