C#使用HTTP方式对接WebService
C#对接WebService的几种方式
1.直接引用服务
添加服务



添加成功后, 会显示服务详细
调用服务

使用HTTPPost调用WebService
option.RequestDataStr = GetHttpRequestXml(strXmlBody);
// 创建一个 HttpClient 对象
using (HttpClient client = new HttpClient())
{
// 创建一个 StringContent 对象,将 SOAP 请求转换为字符串
StringContent content = new StringContent(option.RequestDataStr, System.Text.Encoding.UTF8, "text/xml");
// 添加 SOAPAction 头信息
client.DefaultRequestHeaders.Add("SOAPAction", soapAction);
// 发送 POST 请求,并获取响应
HttpResponseMessage response = client.PostAsync(option.RequestUrl, content).ConfigureAwait(false).GetAwaiter().GetResult();
// 读取响应的内容
string responseContent = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
return responseContent;
}
//获取到xml后, 反解析xml
//Envelope 是根据xml自动生成的model
using (StringReader sr = new StringReader(responseStr))
{
XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
var response = (serializer.Deserialize(sr) as Envelope).Body;
}
根据xml字符串,生成model
获取返回的xml
使用postmen或者SoapUI获取返回的xml,然后复制xml字符串,之后,点击编辑->选择性粘贴->将XML复制为类











![[Realtek sdk-3.4.14b]RTL8197FH-VG+RTL8812F WiFi使用功率限制功能使用说明](https://img-blog.csdnimg.cn/direct/bcbd5ef0744d4994aaea667a05b81787.png)



![[总线仲裁]](https://img-blog.csdnimg.cn/direct/47e1ce6370a94a3eaddb9837eed6682a.png)


