我正在尝试使用HttpClient类发送SOAP消息:
使用REST这样做很容易(代码来自这里):
using System;
using System.Net.Http;
using System.Json;
namespace ConsoleApplication39
{
class Program
{
static void Main(string[] args)
{
HttpClient proxy = new HttpClient();
proxy.GetAsync("http://localhost:14892/api/Bloggers").ContinueWith((r) =>
{
HttpResponseMessage response = r.Result;
response.Content.ReadAsAsync<JsonArray>().ContinueWith(
(a)=>
{
foreach(var w in a.Result)
{
Console.WriteLine(w.ValueOrDefault("Name").ToString());
Console.WriteLine(w.ValueOrDefault("Intrest").ToString());
}
});
});
Console.ReadKey(true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想用SOAP做类似的事情.
我有主机(http://opensearch.addi.dk/2.2/)和POST消息的SOAP消息:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://oss.dbc.dk/ns/opensearch">
<SOAP-ENV:Body>
<ns1:searchRequest>
<ns1:query>dc.title=zorro AND dc.type=bog</ns1:query>
<ns1:agency>100200</ns1:agency>
<ns1:profile>test</ns1:profile>
<ns1:start>1</ns1:start>
<ns1:stepValue>10</ns1:stepValue>
</ns1:searchRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Run Code Online (Sandbox Code Playgroud)
......但是怎么发送呢?
我承认这是我用过的第一个SOAP Web服务,所以我可能不知道我在做什么,但最简单的形式可能是:
HttpClient hc = new HttpClient(); …Run Code Online (Sandbox Code Playgroud)