2011-02-04 61 views
2

我有一个应用程序,我需要发送2个Web请求到同一个Url,但来自不同的源IPEndpoints。ServicePoint不是唯一的本地IPEndpoint

这可以很简单的与做类似的第一个连接:

Dim myWebRequest As Net.HttpWebRequest = Net.WebRequest.Create(MyUrl) 
myWebRequest.ServicePoint.BindIPEndPointDelegate = MyBindIPEndPointFunction 

委托函数MyBindIPEndPointFunction叫我给它正确IPEndpoint,一切工作正常。

但是,在第二个请求中,因为已经有一个ServiceLocal的Url,委托函数MyBindIPEndPointFunction没有被调用,所以我没有办法告诉第二个Web请求绑定到不同的IPEndpoint。

因为网络请求是SSL,所以使用Net.TcpClient对象并不容易,因为我必须处理SSL。

理想情况下,我想强制HttpWebRequest创建一个正常的连接,并关闭它,一旦它完成它的方式 - 没有雇用任何ServicePoint - 这可能吗?我也希望这是所有线程安全和非阻塞,因此我可以在许多线程中启动请求(目前这些线程都使用相同的ServicePoint)。

谢谢。

回答

1

总是可以在代码中设置你的终点,只是创建两个不同的变量名和相同的URL

Private binding1 As New BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly) 
    Private binding2 As New BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly) 
Private WithEvents _Misc1 As Service_Misc.Misc_CallsClient = New Misc_CallsClient(binding1, New EndpointAddress("http://localhost:61928/Misc_Calls.svc")) 
Private WithEvents _Misc2 As Service_Misc.Misc_CallsClient = New Misc_CallsClient(binding2, New EndpointAddress("http://localhost:61928/Misc_Calls.svc")) 
+0

我知道这个问题是有点老了,只是想我会,如果你没有添加potentional答案找到解决方案 – Jim 2011-05-25 17:06:52