从特定 IP 地址发送 SOAP 请求

发布于 2024-12-22 10:00:28 字数 66 浏览 0 评论 0原文

我有一个具有多个 IP 地址的系统。但我只能从一个 IP 地址发起 SOAP 请求。我如何在 VB.NET 中获得它。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧情勿念 2024-12-29 10:00:28

我从来没有这样做过。看起来很复杂。

首先,阅读自定义 ASMX 的方法客户端代理了解重写代理类的GetWebRequest对象的基本技术。

您需要重写GetWebRequest,以便可以获取用于发出请求的ServicePoint。您将设置 BindIPEndPoint 属性指向指向您的方法的委托,该方法将返回正确的 IP 地址。

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

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);
    }
}
☆獨立☆ 2024-12-29 10:00:28

在 WCF 中,当您创建 ChannelFactory 时,您可以指定您的端点(或您希望连接的 IP 地址)。

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

您可以通过指定不同的端点来连接到任意多个不同的 IP。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文