更新时间:2022-11-27 19:16:14
我从未做到过.看起来很复杂.
I've never done this. It looks complicated.
首先,阅读方法自定义ASMX客户端代理,以了解覆盖代理类的GetWebRequest
对象的基本技术.
First, read Ways to Customize your ASMX Client Proxy to learn the basic technique of overriding the GetWebRequest
object of your proxy class.
您将需要覆盖GetWebRequest
,以便可以获取用于进行请求的ServicePoint
.您将 BindIPEndPoint
属性设置为委托指向您将返回正确IP地址的方法.
You will need to override GetWebRequest
so that you can grab the ServicePoint
being used to make the request. You will set the BindIPEndPoint
property to a delegate pointing to a method of yours which will return the correct IP Address.
public partial class Service1
{
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(uri);
request.ServicePoint.BindIPEndPointDelegate = ReturnSpecificIPAddress;
return request;
}
private IPEndPoint BindIPEndPoint(
ServicePoint servicePoint,
IPEndPoint remoteEndPoint,
int retryCount)
{
return new IPEndPoint(IPAddress.Parse("10.0.0.1"), 80);
}
}