views:

961

answers:

9

We are developing a .NET 2.0 winform application. The application needs to access Web Services. Yet, we are encountering issues with users behind proxies.

Popular windows backup applications (think Mozy) are providing a moderately complex dialog window dedicated the proxy settings. Yet, re-implementing yet-another proxy handling logic and GUI looks a total waste of time to me.

What are best ways to deal with proxy with .NET client apps?

More specifically, we have a case where the user has recorded his proxy settings in Internet Explorer (including username and password), so the default proxy behavior of .NET should work. Yet, the user is still prompted for his username and password when launching IE (both fields are pre-completed, the user just need to click OK) - and our winform application still fails at handling the proxy.

What should we do to enforce that the user is not prompted for his username and password when launching IE?

A: 

The easiest way is to use the proxy settings from IE Explorer.

pb
+1  A: 

Look into using the .NET WebProxy class. It has support for automatically selecting the correct default settings.

Jeff Stong
+2  A: 

Use WebProxy and WebRequest classes. Wrap it into you own library just for one time and use everywhere you want work with proxy.

Vokinneberg
+9  A: 

Put this in your application's config file:

<configuration>
  <system.net>
    <defaultProxy>
      <proxy autoDetect="true" />
    </defaultProxy>
  </system.net>
</configuration>

and your application will use the proxy settings from IE. If you can see your web service in IE using the proxy server, you should be able to "see" it from your application.

MusiGenesis
A: 

If you open IE, click OK to the proxy dialog, and then (leaving IE open) try to connect with your winforms app, does your app then work? Or does your app fail to handle the proxy no matter what?

MusiGenesis
A: 

Are your clients that are experiencing proxy problems all on the same network (i.e. are they all using the same proxy server)?

MusiGenesis
A: 

I think the asker understands he has to use WebProxy if the user requires a proxy, the question is "how do I get IE's proxy settings so I don't have to ask the user to type them in to my app as well?"

System.Net.WebProxy.GetDefaultProxy is obsolete, you have to use System.Net.WebRequest.DefaultWebProxy. There is an article describing it at http://msdn.microsoft.com/en-ca/magazine/cc300743.aspx.

Dour High Arch
A: 

Thx Dour,

I'm also facing the same problem. We're on a Proxy server and I wanted to provide username & password inside the code only so that all users can see the company's latest news page. There are lot of users who are not given internet access, so I wish to provide them a readonly (small) webbroswer in my windows form to have a glimps of company's latest news.

There can be different ways by which we can restrict the user from accessing other pages. but the issue is how to provide username & password inside the code itself?

Can somebody help on this one. This looks like a impossible task but I'm not willing to belive that experts don't have any solution for this.

gsvirdi
A: 

I'm also trying to find the answer of this problem.

Mostly we use proxy server to connect to internet in office, I also wanted to Add Proxy information like "Proxy server, port, user name & password" into my Form_Load (Web browser control) code so that this web browser(latest company news) should not give error if the application is accessed on a computer where the internet access is not given to the logged in user.

The WebPermission Class is also not having any kind of help where I can add user name & password inside the code so that the windows form should not give error.

But I'm not able to find any piece of help/code for this purpose.

I Tried this.....
NetworkCredential credentials = new NetworkCredential(userName, passWord); WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true, null, credentials); WebRequest req = WebRequest.Create("http://www.gsvirdi.com"); req.Proxy = proxyObject;

This code does not gives any error, but Internet is still not accessible. Webpage says: Action Canceled. Which means somewhere the authentication is working but server is rejecting the request to connect to internet.

Plz correct me if I'm not understanding this correctly.

gsvirdi