我有一个应用程序,我需要发送2个网络请求到相同的网址,但从不同的来源IPEndpoints。
对于第一个连接,这可以非常简单地完成,只需执行以下操作:
Dim myWebRequest As Net.HttpWebRequest = Net.WebRequest.Create(MyUrl)
myWebRequest.ServicePoint.BindIPEndPointDelegate = MyBindIPEndPointFunction调用委托函数MyBindIPEndPointFunction,并为其提供正确的IPEndpoint,一切正常。
但是,在第二个请求中,因为这个Url已经有一个ServicePoint,所以委托函数MyBindIPEndPointFunction没有被调用,所以我没有办法告诉第二个web请求绑定到不同的IPEndpoint。
因为web请求是SSL,所以只使用Net.TcpClient对象并不容易,因为我必须处理SSL。
理想情况下,我希望强制HttpWebRequest只创建一个普通连接,并在完成连接后关闭它-而不使用任何ServicePoint -这是可能的吗?我还希望这一切都是线程安全和非阻塞的,这样我就可以在许多线程中发出请求(目前它们都使用相同的ServicePoint)。
谢谢。
发布于 2011-05-26 01:03:41
我总是可以在代码中设置端点,只需创建两个具有不同变量名和相同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"))https://stackoverflow.com/questions/4904003
复制相似问题