从代理服务器后面调用Web服务 [英] Calling a webservice from behind a proxy server

查看:55
本文介绍了从代理服务器后面调用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在将使用Web服务(XML SOAP服务)的应用程序(C#)中添加功能.

现在,该应用程序可以(并且主要)可以在具有代理服务器的公司环境中使用.

我了解SOAP服务使用HTTP协议,因此应使用端口80,该端口通常保持打开状态.应用程序可以使用Web服务而无需任何特殊编码是否正确,还是我需要编写特殊代码来检测代理设置或您看到的其他一些问题?

Web服务是Internet上的公共服务.它不在同一网络上.

解决方案

确定.因此,我做了一些实验,结果发现我们确实需要编写一些代码才能使其在代理服务器后面运行.(尽管我本来希望有更好的解决方案)

因此,它实际上可以深入查询用户的代理服务器详细信息,然后为代理服务器配置服务代理类,如下所示:

var networkCredentials =新的NetworkCredential(用户名",密码",域");WebProxy myProxy =新的WebProxy("W.X.Y.Z:NN",true){凭证= networkCredentials};var service = new iptocountry {Proxy = myProxy};字符串结果= service.FindCountryAsString("A.B.C.D");

我写了一个测试类,它使用 IP To Country 免费网络服务./p>

使用上面的代码,我可以成功使用Web服务.

I need to add a functionality in an application (C#) which will use a web service (XML SOAP service).

Now this application can (and mostly) be used in an corporate environment which has a proxy server in place.

I understand the SOAP services use HTTP protocol and hence should use port 80, which is normally kept opened. Is it right that application can use web service without any special coding or I will need to write special code to detect proxy settings or some other issues you see?

EDIT: Webservice is a publicly available service on internet. Its not on same network.

解决方案

OK. So I did some experiments and it turns out that we do need to write some code to make it work from behind the proxy server. (Though I would have prefered a better solution)

So it actually drills down to asking proxy server details from user and then configure the service proxy class for proxy server as below:

var networkCredentials = new NetworkCredential ("username", "password", "domain");
WebProxy myProxy = new WebProxy ("W.X.Y.Z:NN", true) {Credentials = networkCredentials};
var service = new iptocountry { Proxy = myProxy };
string result = service.FindCountryAsString ("A.B.C.D");

I wrote a test class and it uses IP To Country free web service.

Using above code, I could consume the web service successfully.

这篇关于从代理服务器后面调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆