407 Proxy Authentication Required - Not using a Proxy

G

Guest

We have an application that is running fine on several of our customer’s
servers. However, one of our customers is having a problem running the
application. The application works on one of his Windows 2003 servers, but
not on the other one.

The application is a C++ .Net /clr Windows Service. It communicates with
our server by sending and receiving XML using the WebClient object. The
error they are receiving is “The remote server returned an error: (407) Proxy
Authentication Requiredâ€. But, our client swears that he is not going
through a proxy server.

To make things even more odd, if you reboot the server, the application
works for the first connection. The first connection can send and receive
data, but then all subsequent attempts fail with the proxy error.

The code is pretty basic:

Uri ^SourceUri = gcnew Uri(RequestUrl);
WebClient ^client = gcnew WebClient();
//----------create proxy server object -----------------------
NetworkCredential^ UserCreds = nullptr;
WebProxy^ proxyObject = nullptr;
//----------is user using a proxy-----------------------------
if (pConfig->UseProxyServer == true){
UserCreds = gcnew NetworkCredential( pConfig->ProxyUserName,
pConfig->ProxyPassword, pConfig->ProxyUserDomain );
proxyObject = gcnew WebProxy( String::Concat("http://",
pConfig->ProxyServerName, ":", pConfig->ProxyServerPort, "/") , true);
proxyObject->Credentials = UserCreds;
client->Proxy = proxyObject;
}else{
//-------------use default credentials-------------------------
client->UseDefaultCredentials = true;
}
//-------------------------------------------------------------
client->Headers->Add("Content-Type", "application/x-www-form-urlencoded;
charset=UTF-8");
array<Byte> ^byteArray = Encoding::UTF8->GetBytes(XmlDataToSend);
array<Byte> ^responseArray = client->UploadData(SourceUri->AbsoluteUri,
"POST", byteArray);

Any ideas why the code would work the first time, but then fail with a proxy
error on subsequent attempts? Are there any tests I can run to help debug
this problem? Any help would be greatly appreciated.
 
J

Jeffrey Tan[MSFT]

Hi Gallan,

This issue should be a System.Net.WebClient programming problem and does
not have too much relation with C++/CLI language. Anyway, I will help you
on it.

Based on my experience, the error should be returned by the proxy server,
if the customer did not have proxy configured, this is really strange. Can
you ask the customer to check if there is any proxy setting in IE
Tools->Internet Options -> Connections ->LAN settings? I suspect they may
get a proxy setting which they are unaware of.

Additionally, if they do no have proxy, why do you still explicitly pass
the proxy address and username/password through NetworkCredential and
WebProxy. If there is no proxy, you should specify empty proxy through
GlobalProxySelection.GetEmptyWebProxy method and use the
System.Net.CredentialCache.DefaultCredentials.

Finally, if you want to understand the details of the WebClient
communications, you may enable the System.Net log tracing. In the trace
log, you may examine whether your WebClient is communicating to any proxy.
Please refer to the 2 links below to enable the trace log:
"Enabling Network Tracing"
http://msdn2.microsoft.com/en-us/library/a6sbz1dx.aspx
"How to: Configure Network Tracing"
http://msdn2.microsoft.com/en-us/library/ty48b824.aspx

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top