客户端发送SOAP请求并接收响应尝试创建一个C#客户机(将作为Windows服务开发),该客户端向Web服务发送SOAP请求(并获取结果)。从这里问题我看到了这个代码:protected virtual WebRequest CreateRequest(ISoapMessage soapMessage){
var wr = WebRequest.Create(soapMessage.Uri);
wr.ContentType = "text/xml;charset=utf-8";
wr.ContentLength = soapMessage.ContentXml.Length;
wr.Headers.Add("SOAPAction", soapMessage.SoapAction);
wr.Credentials = soapMessage.Credentials;
wr.Method = "POST";
wr.GetRequestStream().Write(Encoding.UTF8.GetBytes(soapMessage.ContentXml), 0, soapMessage.ContentXml.Length);
return wr;}public interface ISoapMessage{
string Uri { get; }
string ContentXml { get; }
string SoapAction { get; }
ICredentials Credentials { get; }}看起来不错,有人知道如何使用它,以及它是否是最佳实践?
3 回答
- 3 回答
- 0 关注
- 779 浏览
添加回答
举报
0/150
提交
取消