简体   繁体   English

使用不同的 IP 进行网络服务调用

[英]using a different IP for webservice calls

Scenario - multiple computers at site (db, app, report etc) all systems are functioning right now using the assigned IP address from customer.场景 - 站点上的多台计算机(数据库、应用程序、报告等)所有系统现在都在使用客户分配的 IP 地址运行。

New twist is this - the system that generates the web service calls to external data providers (state run websites) needs to originate the traffic from a different IP address.新的变化是——生成对外部数据提供者(国营网站)的 Web 服务调用的系统需要从不同的 IP 地址发起流量。 The new IP address is the only one that is allowed to go through the firewall, the internal data traffic will stay inside the enclave of systems, communicating with each other.新的 IP 地址是唯一允许通过防火墙的地址,内部数据流量将留在系统的飞地内,相互通信。 The same machine (app server) is the interface with the user using a webserver, having two (or more) IP addresses assigned to it.同一台机器(应用程序服务器)是与使用网络服务器的用户的接口,分配有两个(或更多)IP 地址。

Here is the question - in the code, is there a way to have the web service originator call to use a different IP address to communicate with the outside world?这里有一个问题——在代码中,有没有办法让 Web 服务发起方调用使用不同的 IP 地址与外界进行通信?

It may be difficult to implement through httpclient, but HttpWebRequest can help you if you use asp.net.通过httpclient 实现可能比较困难,但是如果你使用asp.net, HttpWebRequest可以帮助你。

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://stackoverflow.com");

        System.Net.WebProxy proxy = new WebProxy("the IP", 80);
        request.Proxy = proxy;
        using (WebResponse response = request.GetResponse())
        {
            using (TextReader reader = new StreamReader(response.GetResponseStream()))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                    Console.WriteLine(line);
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM