简体   繁体   English

Web服务代理设置

[英]web service proxy setting

In c# 4.0, I have a web service called ManufacturerContactDetails. 在c#4.0中,我有一个名为ManufacturerContactDetails的Web服务。 I am calling that web service from a windows app using the following: 我使用以下内容从Windows应用程序调用该Web服务:

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

However, I would like to set the web proxy server that the soap client uses. 但是,我想设置soap客户端使用的Web代理服务器。 I've had a look for a ws.Proxy property but it doesn't exist. 我已经找了一个ws.Proxy属性,但它不存在。 I don't want to use the one from internet explorer. 我不想使用来自Internet Explorer的那个。

How do I set the web proxy server to use? 如何设置要使用的Web代理服务器?

If this is a WCF client there is no Proxy property. 如果这是WCF客户端,则没有Proxy属性。 You could try this instead: 你可以试试这个:

var proxy = new WebProxy("proxy.foo.com", true);
proxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = proxy;

and then do the call: 然后拨打电话:

using (var ws = new ManufacturerContactDetailsWebServiceSoapClient())
{
    var cd = ws.GetContactDetails("Google");
}

Create the app config file containing the following 创建包含以下内容的应用配置文件

<system.net>
    <defaultProxy useDefaultCredentials="true">
        <proxy usesystemdefault="True" bypassonlocal="True"/>
    </defaultProxy>
</system.net>

More info here http://blogs.infosupport.com/blogs/porint/archive/2007/08/14/Configuring-a-proxy_2D00_server-for-WCF.aspx 更多信息,请访问http://blogs.infosupport.com/blogs/porint/archive/2007/08/14/Configuring-a-proxy_2D00_server-for-WCF.aspx

Bye 再见

Add this to your app.config or web.config: 将其添加到app.config或web.config:

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

Try adding this to app.config file. 尝试将此添加到app.config文件。

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

Add proxy in the proxy tag. 在代理标记中添加代理。 Use the default proxy tag in the system.net setting in the app.config. 使用app.config中system.net设置中的默认代理标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM