我正在尝试使用 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);
}
}
}
我想用 SOAP 做一些类似的事情。
我有主机(http://opensearch.addi.dk/2.2/)和要发布的 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>
...但是如何发送呢?
我承认这是我用过的第一个 SOAP Web 服务,所以我可能不知道我在做什么,但最简单的形式可能是:
HttpClient hc = new HttpClient();
hc.BaseAddress = new Uri("http://opensearch.addi.dk/2.2/");
HttpContent content = *... something*
HttpResponseMessage rm = await hc.PostAsync("http://opensearch.addi.dk/2.2/", content);
我假设应该以某种方式通过 HttpContent.Create(..) 之类的 HttpContent 静态方法创建 SOAP 消息,但我无法让它工作......
我知道这是一个愚蠢的问题,但我仍然需要帮助 :) !
蒂亚...