2011-03-05 124 views
5

在c#4.0中,我有一個名爲ManufacturerContactDetails的Web服務。我使用以下調用從Windows應用程序,Web服務:Web服務代理設置

var ws = new ManufacturerContactDetailsWebServiceSoapClient(); 
ContactDetails cd = ws.GetContactDetails("Google"); 

不過,我想設置的SOAP客戶端使用Web代理服務器。我查看了ws.Proxy屬性,但它不存在。我不想使用Internet Explorer中的那個。

如何設置Web代理服務器使用?

+0

不'ManufacturerContactDetailsWebServiceSoapClient'從派生什麼類型的? – 2011-03-05 17:07:01

回答

1

嘗試將此添加到app.config文件。

<system.net> 
    <defaultProxy enabled="false" useDefaultCredentials="false"> 
     <proxy/> 
    </defaultProxy> 
</system.net> 

在代理標籤中添加代理。 使用app.config中system.net設置中的默認代理標記。

7

如果這是WCF客戶端,則不存在代理屬性。你可以代替試試這個:

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"); 
} 
6

添加到您的app.config或web.config中:

<system.net> 
    <defaultProxy enabled="true"> 
    <proxy proxyaddress="http://111.222.333.444:80"/> 
    </defaultProxy> 
</system.net>