Send SOAP Request from a specific IP address

泄露秘密 提交于 2019-12-05 10:47:48

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

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.

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