发送来自特定IP地址的SOAP请求
答
在WCF中,当您创建ChannelFactory时,您可以指定您的端点(或您希望连接的IP地址)。
Dim factory As ChannelFactory(Of IChatServiceChannel)
factory = New DuplexChannelFactory(Of IChatServiceChannel)(callbackObject, binding, endpoint)
Dim Channel = factory.CreateChannel()
您可以连接到许多不同的IP地址,只要你想这样通过指定不同的端点。
+0
不是终点,而是SOAP请求初始化的起点。 @RyanFishman – 2011-12-28 08:10:53
+1
另外,他说他使用的是Web引用,所以他不能使用你的技术。 – 2011-12-28 08:15:00
答
我从来没有这样做过。看起来很复杂。
首先,阅读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);
}
}
Web引用或服务引用? – 2011-12-27 04:14:25
Web引用.. – 2011-12-28 08:09:49