我有一个具有多个IP地址的系统。但我只能从一个IP地址发起SOAP请求。我如何在VB.NET中获得它。
发布于 2011-12-28 16:34:17
我从来没这么做过。看起来很复杂。
首先,阅读Ways to Customize your ASMX Client Proxy以了解覆盖代理类的GetWebRequest对象的基本技术。
您将需要覆盖GetWebRequest,以便获取用于发出请求的ServicePoint。您将BindIPEndPoint属性设置为一个委托,该委托指向您的方法,该方法将返回正确的IP地址。
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);
}
}发布于 2011-12-27 05:22:24
在WCF中,当您创建ChannelFactory时,您可以指定您的端点(或您希望连接到的IP地址)。
Dim factory As ChannelFactory(Of IChatServiceChannel)
factory = New DuplexChannelFactory(Of IChatServiceChannel)(callbackObject, binding, endpoint)
Dim Channel = factory.CreateChannel()您可以像这样通过指定不同的端点连接到任意多个不同的IP。
https://stackoverflow.com/questions/8587647
复制相似问题