Soap中的WebRequest [英] WebRequest within Soap

查看:47
本文介绍了Soap中的WebRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能够为我提供帮助,我已经有一段时间没有用C#编程了.我敢肯定答案会很简单,但我只是无法理解.

I am hoping someone will be able to help me, I haven't been programming in C# for a while. I'm sure the answer will be simple but i just can't get my head around it.

我有以下内容,在这里我称为System.Web.Services.Protocols.SoapHttpClientProtocol.我只列出了我打过的许多电话之一.

I have the following, where i call System.Web.Services.Protocols.SoapHttpClientProtocol. I have included just one of the many calls that i have.

public partial class ExchangeService : System.Web.Services.Protocols.SoapHttpClientProtocol   {

//Lots of code using Soap 

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("getDetailsLite", RequestNamespace="http://www.MySite.com/ExchangeService/", ResponseNamespace=" http://www.MySite.com/ExchangeService/", ", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("Result", IsNullable=true)]
    public GetDetailsLiteResp getDetailsLite(getDetailsLiteReq request) {
        object[] results = this.Invoke("getDetailsLite", new object[] {
                    request});
        return ((getDetailsLiteResp)(results[0]));
    }

    public void getDetailsLiteAsync(getDetailsLiteReq request) {
        this. getDetailsLiteAsync(request, null);
    }

    public void getDetailsLiteAsync (getDetailsLiteReq request, object userState) {
        if ((this.getDetailsLiteOperationCompleted == null)) {
            this.getDetailsLiteOperationCompleted = new System.Threading.SendOrPostCallback(this.OngetDetailsLiteOperationCompleted);
        }
        this.InvokeAsync("getDetailsLite", new object[] {
                    request}, this. getDetailsLiteOperationCompleted, userState);
    }
}

我想重写SoapHttpClientProtocol调用的WebRequest.SoapHttpClientProtocol看起来像这样(我相信是从System.Web.Services.dll中调用的)

I want to override the WebRequest that the SoapHttpClientProtocol calls. The SoapHttpClientProtocol looks like this (which I believe is called from System.Web.Services.dll)

namespace System.Web.Services.Protocols  {
    public class SoapHttpClientProtocol : HttpWebClientProtocol    {
    public SoapHttpClientProtocol();
    public SoapProtocolVersion SoapVersion { get; set; }
    protected IAsyncResult BeginInvoke(string methodName, object[] parameters, AsyncCallback callback, object asyncState);
    public void Discover();
    protected object[] EndInvoke(IAsyncResult asyncResult);
    protected virtual XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize);

    //This line is the one i am talking about
    protected override WebRequest GetWebRequest(Uri uri);

    protected virtual XmlWriter GetWriterForMessage(SoapClientMessage message, int bufferSize);
    protected object[] Invoke(string methodName, object[] parameters);
    protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback);
    protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback, object userState);
    }
}

我需要保护覆盖的WebRequest GetWebRequest(Uri uri)如下所示:

I need protected the override WebRequest GetWebRequest(Uri uri ) to look like this:

protected override WebRequest GetWebRequest(Uri uri)  {
    HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);
    webRequest.KeepAlive = false;
    webRequest.ProtocolVersion=HttpVersion.Version10;
    return webRequest;
}

有人知道我会怎么做吗?我本可以直接在SoapHttpClientProtocol内部对其进行编辑,因此99%的用户肯定我不应该这样做.

Does anyone know how i would do this? I am uanble to edit it directly inside of the SoapHttpClientProtocol which im 99% sure i shouldn't be doing anyway.

感谢您可能提供的帮助

推荐答案

子类吗? GetWebRequest 在根类 WebClientProtocol 中标记为虚拟,因此您可以覆盖该方法.

Subclass it? GetWebRequest is marked as virtual in the root class WebClientProtocol, so you can override the method.

public class MyHttpProtocol : SoapHttpClientProtocol  
{
    public override WebRequest GetWebRequest(Uri uri)
    {
        // Base request:
        WebRequest request = base.GetWebRequest(uri);

        // You code goes here...

        // Return...
        return request;
    }
}

然后根据需要在服务类中使用 MyHttpProtocol .

Then use MyHttpProtocol as needed within your service class.

这篇关于Soap中的WebRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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