我希望有人能够帮助我,我已经有一段时间没有用 C# 编程了。我相信答案会很简单,但我无法理解它。
我有以下内容,我称之为 System.Web.Services.Protocols.SoapHttpClientProtocol。我只包括了我拥有的众多电话之一。
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 调用的)
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) 看起来像这样:
protected override WebRequest GetWebRequest(Uri uri) {
HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);
webRequest.KeepAlive = false;
webRequest.ProtocolVersion=HttpVersion.Version10;
return webRequest;
}
有谁知道我会怎么做?我不能直接在 SoapHttpClientProtocol 内部编辑它,我 99% 肯定我不应该这样做。
感谢您提供的任何帮助