Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send SOAP Request from a specific IP address

Tags:

soap

vb.net

asmx

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.

like image 403
Akhil K Nambiar Avatar asked Nov 04 '22 09:11

Akhil K Nambiar


1 Answers

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);
    }
}
like image 182
John Saunders Avatar answered Nov 09 '22 17:11

John Saunders