本文介绍了如何将 HTTP 标头添加到 SOAP 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果可以将 HTTP 标头添加到肥皂客户端 Web 服务调用,有人可以回答我吗?上网后,我唯一发现的就是如何添加 SOAP 标头.
Can someone answer me if it is possible to add HTTP header to soap client web-service calls. After surfing Internet the only thin I found was how to add SOAP header.
代码如下所示:
var client =new MyServiceSoapClient();
//client.AddHttpHeader("myCustomHeader","myValue");//There's no such method, it's just for clearness
var res = await client.MyMethod();
更新:
The request should look like this
POST https://service.com/Service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://www.host.com/schemas/Authentication.xsd/Action"
Content-Length: 351
MyHeader: "myValue"
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header/>
<s:Body>
<myBody>BodyGoesHere</myBody>
</s:Body>
</s:Envelope>
信封中的Header属性应该为空
Header property in the envelop should be empty
推荐答案
试试这个:
SoapServiceClient client = new SoapServiceClient();
using(new OperationContextScope(client.InnerChannel))
{
// // Add a SOAP Header (Header property in the envelope) to an outgoing request.
// MessageHeader aMessageHeader = MessageHeader
// .CreateHeader("MySOAPHeader", "http://tempuri.org", "MySOAPHeaderValue");
// OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader);
// Add a HTTP Header to an outgoing request
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers["MyHttpHeader"] = "MyHttpHeaderValue";
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name]
= requestMessage;
var result = client.MyClientMethod();
}
请参阅 这里了解更多详情.
See here for more detail.
这篇关于如何将 HTTP 标头添加到 SOAP 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!