Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I am writing an application that will be distributed to our clients, who may and may not have a proxy server. There are numerous calls to a web service that is on our public server. We use a proxy server at our company and when I run my application and it hits a call to the web service it fails:

The request failed with HTTP status 407: Proxy Authentication Required.

 

I can get the code to work if I hard code the values that work for our proxy server i.e.

 

Dim WebServices As New WebServices.GeneralWebServices
Dim dsResults As New DataSet
Dim nc As New Net.NetworkCredential("user", "password")
Dim wp As New Net.WebProxy("http://1.1.1.1:8000")
wp.Credentials = nc
WHLWebServices.Proxy = wp

dsResults = WebServices.call()

 

But in the case of this being on the client I won't know the credential for username, password & server name.

 

I tried using

 

System.Net.CredentialCache.DefaultNetworkCredentials

System.Net.CredentialCache.DefaultCredentials

System.Net.WebProxy.GetDefaultProxy

 

These fail to work. The values appear to be empty for the first two but I believe that even though you cannot view these details the values will still be passed. The last one has been deprecated and also does not appear to work.

 

Can somebody please help?

 

Cheers, Dave.

  • Administrators
Posted

If they have already configured IE with the correct proxy details then you should be able to use the GetDefaultProxy along with the CredentialCache.DefaultCredentials, to assign the correct proxy credentials.

 

Other than that you could prompt them for the proxy's user name and password and store that in an encrypted form somewhere...

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Hi,

 

Firstly thanks once again for your help.

 

Two questions:

 

1.

You suggested:

you should be able to use the GetDefaultProxy along with the CredentialCache.DefaultCredentials, to assign the correct proxy credentials

 

I tried:

Dim wp As New Net.WebProxy("http://1.1.1.1:1")
wp.Credentials = System.Net.CredentialCache.DefaultCredentials
WHLWebServices.Proxy = wp

 

And...

 

Dim wp As New Net.WebProxy("http://1.1.1.1")
wp = System.Net.WebProxy.GetDefaultProxy
WHLWebServices.Proxy = wp

 

But these fail to work, how would I use these correctly? Also the declaration for the proxy, does this still need the proxy's address?

 

2.

 

If I take your second option, will I need to ask the user for the proxy server's address to there also?

 

Cheers, Dave.

Posted

I also tried:

Dim wp As New Net.WebProxy("http://1.1.1.1")
wp = System.Net.WebProxy.GetDefaultProxy
wp.Credentials = System.Net.CredentialCache.DefaultCredentials
WHLWebServices.Proxy = wp

 

No luck!

  • Administrators
Posted

Odd indeed. Do they all throw the same 407 error? Is this being run as a normal user application from their desktop or is something more complex happening (i.e. citrix or being run as a service)?

 

When you are passing a username / password have you tried the overload that also accepts a domain?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Hi,

 

I have tried the overloaded version but didn't manage to get that to work.

 

I don't think there is anything like citrix involved with this. But I am starting to thing that our IIT deparment have set this proxy server up in a slightly weired way. Is there anywat when configuring a proxy server thet you can stop a client's machine from accepting default credentials?

 

The thing is that the web server machine does not use the proxy server so it is almost definitely a client issue. But as we are intending to distribute this application to clint's who also may behind a proxy server I want to make sure that it will work.

 

I have not tried browsing to the web service from a browser on this machine I suspect it will work as it is the client machine that is preventing this from working. Saying that I will try it tomorrow when I am back at work.

  • Administrators
Posted

When you are testing this are you testing it with the client and the server on the same network or are you having to go through the proxy to access the web server?

 

If both the client and server are on the same side of the proxy then that could actually be the problem - the proxy itself may need configuring to operate in this situation.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 1 month later...
Posted

Sorry for not replying to this sooner.

 

My solution in the end was to write a class that attempts to FTP a small text file by:

 

1. Providing no credentials

2. Providing default credentials

3. Providing specific credentials.

 

If the user fails the 1st and 2nd test and they have not provided specific credentials, they are asked for them and saved in isolated storage for later use.

 

In most cases it will be fine. It is just in the case of a proxy server such as our's that always asks for credentials everytime you request to go outside of the proxy. Anyway it seems to work ok.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...