C#使用WebProxy实现代理访问webservice

1.问题描述

标题写的有点含糊不清,不好意思语言表达能力欠佳。。事情是这样的!

事情是这样的,在A服务器上有一个webservice,B计算机和C计算机都可以ping通A服务器,但是C计算机的ip备案了而B计算机的ip没有备案,导致我写的一个小程序放在B计算机上调用A服务器的webservice的时候提示我ip非法。
那么该如何让这个小程序能在B计算机上正常使用呢?答案是代理服务器!

2. windows如何搭建代理服务器

CCProxy是一款国产代理服务器软件,操作简便

CCProxy官网:http://www.ccproxy.com/
在这里插入图片描述

3.C#代码

在C计算机上搭建好代理服务器后,B的C#程序使用WebProxy完成代理操作

在C#程序中设置WebProxy的ip和端口号,该ip和端口号应设置为C计算机代理服务器的ip和端口号!
代码如下:

this.accessService = new TmriJaxRpcOutNewAccessService()//这是通过wsdl生成的我要引用的webservice的类
{
    Url = this._serviceAddress//这是webservice的地址,例如:http://192.168.100.100:8090/services/
};
string proxyip = Properties.Settings.Default.proxyip;//代{过}{滤}理ip
int proxyport = Properties.Settings.Default.proxyport;//代{过}{滤}理端口
if (Properties.Settings.Default.proxyip != "")
{
    System.Net.WebProxy owebProxy = new System.Net.WebProxy(proxyip.Trim(), proxyport);//创建代{过}{滤}理
    owebProxy.UseDefaultCredentials = true;
    this.accessService.Proxy = owebProxy;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章