[英]web service proxy setting
在c#4.0中,我有一個名為ManufacturerContactDetails的Web服務。 我使用以下內容從Windows應用程序調用該Web服務:
var ws = new ManufacturerContactDetailsWebServiceSoapClient();
ContactDetails cd = ws.GetContactDetails("Google");
但是,我想設置soap客戶端使用的Web代理服務器。 我已經找了一個ws.Proxy屬性,但它不存在。 我不想使用來自Internet Explorer的那個。
如何設置要使用的Web代理服務器?
如果這是WCF客戶端,則沒有Proxy屬性。 你可以試試這個:
var proxy = new WebProxy("proxy.foo.com", true);
proxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = proxy;
然后撥打電話:
using (var ws = new ManufacturerContactDetailsWebServiceSoapClient())
{
var cd = ws.GetContactDetails("Google");
}
創建包含以下內容的應用配置文件
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy usesystemdefault="True" bypassonlocal="True"/>
</defaultProxy>
</system.net>
再見
將其添加到app.config或web.config:
<system.net>
<defaultProxy enabled="true">
<proxy proxyaddress="http://111.222.333.444:80"/>
</defaultProxy>
</system.net>
嘗試將此添加到app.config文件。
<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
</defaultProxy>
</system.net>
在代理標記中添加代理。 使用app.config中system.net設置中的默認代理標記。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.