在c#4.0中,我有一个名为ManufacturerContactDetails的Web服务。我使用以下内容从Windows应用程序调用该Web服务:
var ws = new ManufacturerContactDetailsWebServiceSoapClient();
ContactDetails cd = ws.GetContactDetails("Google");
但是,我想设置soap客户端使用的Web代理服务器。我已经找了一个ws.Proxy属性,但它不存在。我不想使用来自Internet Explorer的那个。
如何设置要使用的Web代理服务器?
答案 0 :(得分:9)
创建包含以下
的应用配置文件<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy usesystemdefault="True" bypassonlocal="True"/>
</defaultProxy>
</system.net>
再见
答案 1 :(得分:8)
如果这是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");
}
答案 2 :(得分:7)
将此添加到您的app.config或web.config:
<system.net>
<defaultProxy enabled="true">
<proxy proxyaddress="http://111.222.333.444:80"/>
</defaultProxy>
</system.net>
答案 3 :(得分:2)
尝试将此添加到app.config文件。
<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
</defaultProxy>
</system.net>
在代理标记中添加代理。 使用app.config中system.net设置中的默认代理标记。