在对SoapHttpClient服务的调用中添加HTTP标头 [英] adding http headers in call to SoapHttpClient service

查看:290
本文介绍了在对SoapHttpClient服务的调用中添加HTTP标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用我们合作伙伴之一提供的服务.我几乎没有得到指示,但被告知安全性应为PasswordDigest.我查了一下,立刻看到了很多有关WSE的参考,于是我就去了.这非常容易实现,并且我很快就可以在邮件的SOAP标头中使用PasswordDigest获得标准的WSE用户令牌.

I have to consume a service provided by one of our partners. I was given little direction, but was told the security was to be PasswordDigest. I looked it up and immediatly saw lots of references to WSE, so off I went. It was very easy to implement and in no time I had a standard WSE user token using PasswordDigest sitting in the SOAP headers of my messages.

今天我们开始测试时,错误消息立即告诉我,事情不对劲.事实证明,合作伙伴不在SOAP标头中查找,而是希望在http标头中提供安全信息.

When we started testing today I was immediatly told (by the error message) that things weren't right. Turns out, out partner doesn't look in the SOAP header, but rather wants the security info in the http header.

我看过很多关于如何将自定义http标头添加到代理类的文章,但是我的代理继承自SoapHttpClientProtocol,没有添加标头集合.我当时在看原始的httpWebRequest,但是我有一种特定的访问方法,该方法具有一些要处理的复杂参数(而且感觉像是在回话).

I have seen lots of articles on how to add custom http headers to a proxy class, but my proxy inherits from SoapHttpClientProtocol which doesn't have a headers collection to add to. I was looking at making a raw httpWebRequest, but I have a specific method to access that has some complex parameters to deal with (and besides it feels like going backwords).

向没有GetWebRequest方法的服务代理类中添加自定义http标头的最佳方法是什么?

What is the best way to add custom http headers to a service proxy class that doesn't have a GetWebRequest method?

供参考:

代理类简化:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.3053")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="MtomServiceSoap11", namespace="http://ws.xxxxxxx.com/")]
public partial class MtomServiceService : System.Web.Services.Protocols.SoapHttpClientProtocol {

我需要调用的目标方法:

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("uploadDocumentResponse", Namespace="http://ws.edsmtom.citizensfla.com/")]
public uploadDocumentResponse uploadDocument([System.Xml.Serialization.XmlElementAttribute(Namespace="http://ws.xxxxxxx.com/")] uploadDocumentRequest uploadDocumentRequest) {
    object[] results = this.Invoke("uploadDocument", new object[] {
        uploadDocumentRequest});
        return ((uploadDocumentResponse)(results[0]));
    }
}

对服务的实际调用很简单.传入的对象不是:

The actual call to the Service is simple. The objects being pass in are not:

request.criteria = docCriteria;
request.document = document;
var result = service.uploadDocument(request);

谢谢.

推荐答案

计算得出,发布30分钟后,我会偶然发现答案.虽然代理类声明没有创建GetWebRequest方法,但其基类System.Web.Services.Protocols.SoapHttpClientProtocol拥有它,可以重写它.

It figures that 30 minutes after posting I would stumble across the answer. While the proxy class decelaration does not create a GetWebRequest method, its base class System.Web.Services.Protocols.SoapHttpClientProtocol has it and it can be overridden.

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
    var request = base.GetWebRequest(uri);
    request.Headers.Add("blah", "blah"); // <----
    return request;
}

这篇关于在对SoapHttpClient服务的调用中添加HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆