Send SOAP Request from a specific IP address

2019-04-29 16:10发布

问题:

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.



标签: vb.net soap asmx