Send SOAP Request from a specific IP address

[亡魂溺海] 提交于 2019-12-07 05:39:43

问题


I have a system with multiple IP address. But I'm allowed to initiate SOAP Request only from one IP address. How do I obtain that in VB.NET.


回答1:


I've never done this. It looks complicated.

First, read Ways to Customize your ASMX Client Proxy to learn the basic technique of overriding the GetWebRequest object of your proxy class.

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);
    }
}



回答2:


In WCF when you create your ChannelFactory you can specify your endpoint (or IP address to which you wish to connect).

 Dim factory As ChannelFactory(Of IChatServiceChannel)
 factory = New DuplexChannelFactory(Of IChatServiceChannel)(callbackObject, binding, endpoint)
 Dim Channel = factory.CreateChannel()

You can connect to as many different IPs as you want like this by specifying different endpoints.



来源:https://stackoverflow.com/questions/8587647/send-soap-request-from-a-specific-ip-address

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!