請問怎樣通過代理服務器引用internet上的webservice(c#)

kuangxiang007 2004-10-07 09:39:09
我在一個class里引用到外部的webservice﹐但要通過proxy并用授權帳號密碼來連出去﹐我查到一些資料只是輕微的描述了一下用WebProxy﹐用this.Proxy = proxy;設定即可﹐但我在class里用this卻沒有Proxy的屬性﹐誰能提供完整的代碼實現過程﹐請多指教﹐謝謝。


我繼承System.Web.Services.Protocols.SoapHttpClientProtocol來寫﹐我不知要怎樣繼承和設定﹐執行的第一行代碼就提示下列錯誤信息了﹕

類型 'System.InvalidOperationException' 的未處理例外狀況發生於 system.web.services.dll

其他資訊: WebServiceBindingAttribute 是 proxy 類別的必要項。
...全文
237 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangxt 2004-10-15
  • 打赏
  • 举报
回复
帮你顶
liuzxit 2004-10-15
  • 打赏
  • 举报
回复
this.oWebService = new PWebService.PWebService();
string ProxyHost = "proxy.csdn.net";
int ProxyPort = 80;
string ProxyUser = "loginName";
string ProxyPassword = "loginPsw";
string ProxyDomain = "domain";
System.Net.WebProxy oWebProxy = new System.Net.WebProxy(ProxyHost,ProxyPort);
oWebProxy.Credentials = new System.Net.NetworkCredential( ProxyUser, ProxyPassword,ProxyDomain);
oWebService.Proxy = oWebProxy;
kuangxiang007 2004-10-07
  • 打赏
  • 举报
回复
這個例子我也找到﹐不過就是有上面我說的錯誤提示﹐順便問一下那些中括號的語句有什么用的﹐不寫行不行﹐例如﹕[System.Diagnostics.DebuggerStepThroughAttribute()]
Tomgus 2004-10-07
  • 打赏
  • 举报
回复
访问http://www.webservicex.net/globalweather.asmx时vs.net的生成的代理类的代码,我的代理服务器没有用户名和密码我没法试,不代密码的方法:
其中
System.Net.WebProxy myProxy
=new System.Net.WebProxy("192.1.1.1",8080);
this.Proxy=myProxy;
就是设置代理服务器的代码




[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="GlobalWeatherSoap", Namespace="http://www.webserviceX.NET")]
public class GlobalWeather : System.Web.Services.Protocols.SoapHttpClientProtocol {

/// <remarks/>
public GlobalWeather() {
this.Url = "http://www.webservicex.net/globalweather.asmx";
//指定代理服务器
System.Net.WebProxy myProxy
=new System.Net.WebProxy("192.1.1.1",8080);
this.Proxy=myProxy;
}

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.webserviceX.NET/GetWeather", RequestNamespace="http://www.webserviceX.NET", ResponseNamespace="http://www.webserviceX.NET", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string GetWeather(string CityName, string CountryName) {
object[] results = this.Invoke("GetWeather", new object[] {
CityName,
CountryName});
return ((string)(results[0]));
}

/// <remarks/>
public System.IAsyncResult BeginGetWeather(string CityName, string CountryName, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetWeather", new object[] {
CityName,
CountryName}, callback, asyncState);
}

/// <remarks/>
public string EndGetWeather(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}

/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.webserviceX.NET/GetCitiesByCountry", RequestNamespace="http://www.webserviceX.NET", ResponseNamespace="http://www.webserviceX.NET", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string GetCitiesByCountry(string CountryName) {

object[] results = this.Invoke("GetCitiesByCountry", new object[] {
CountryName});

return ((string)(results[0]));
}

/// <remarks/>
public System.IAsyncResult BeginGetCitiesByCountry(string CountryName, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetCitiesByCountry", new object[] {
CountryName}, callback, asyncState);
}

/// <remarks/>
public string EndGetCitiesByCountry(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}
}
}

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧