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