Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

ASP.NET / WebDAV - 502 (Bad Gateway)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee Wilson - 26 Jun 2007 11:16 GMT
The concept is to display the current user's inbox (located on a remote
Exchange 2003 server) from the intranet home page. The following code has
been written:
string studentLoginId = "LOGINID";
string studentPassword = "PASSWORD";

string studentInbox = string.Format("{0}{1}/{2}/",
Properties.Settings.Default.StudentExchangeLoc, studentLoginId,
Properties.Settings.Default.InboxFolder);

string inboxQuery = "<?xml version=\"1.0\"?>"
                   + "<D:searchrequest xmlns:D = \"DAV:\"><D:sql>"
                   + "SELECT \"urn:schemas:httpmail:datereceived\""
                   + ",\"urn:schemas:httpmail:normalizedsubject\""
                   + ",\"urn:schemas:httpmail:importance\""
                   + ",\"urn:schemas:httpmail:read\""
                   + " FROM scope('shallow traversal of \"" + studentInbox
+ "\"')"
                   + " WHERE \"DAV:ishidden\" = " + false
                   + " AND \"DAV:isfolder\" = " + false
                   + "</D:sql></D:searchrequest>";

byte[] bytes = System.Text.Encoding.UTF8.GetBytes(String.Format(inboxQuery,
studentInbox));

HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create(studentInbox);

request.Method = "SEARCH";
request.ContentLength = bytes.Length;
request.ContentType = "text/xml";

request.Credentials = new NetworkCredential(studentLoginId,
studentPassword);

using (System.IO.Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}

WebResponse response = (HttpWebResponse)request.GetResponse();

System.IO.StreamReader reader = new
System.IO.StreamReader(response.GetResponseStream());

string xml = reader.ReadToEnd();

System.Xml.XmlDocument xmlDoc = new XmlDocument();

xmlDoc.LoadXml(xml);

When this is run locally on my development machine, everything works fine.
Once deployed to the intranet there is an exception: (502 Bad Gateway). The
exception occurs when the GetRequestStream() method is called. For testing
purposes, the web application was deployed to the Exchange server, and it
worked as intended.

Any clues would be fantastic,

Lee Wilson
Steven Cheng[MSFT] - 27 Jun 2007 04:54 GMT
Hi lee,

From your description, you're using httpwebrequest component to send some
WEBDAV xml request to exchange server and it works well on
development(return inbox data), but fails(with 502 badrequest error) when
deployed to the internal webserver, correct?

As for this problem, since the same code used to work on dev machine, so
the code logic should be ok. Also, I'd like to confirm the following things:

** As you mentioend ASP.NET, so the WEBDAV request code is executed in
ASP.NET web application(in web page's code) ,correct?

** When running on development machine, is it also executing in a ASP.NET
applicaiton. If so, whether you're using the VS 2005 web test
server(through file system web site project) or IIS hosted project?  

Based on my experience, such 502 BADREQUEST error usually indicate that
there are some problem with the intermediate network connection. For
example, faild to locate the proxy server or deny by the firewall/proxy
server.  So in the above items, I ask you to confirm whether you're using
web test server in development machine. Because web test server is a
winform program which running under the current logon user while IIS hosted
ASP.NET process running under a non-interactive process account. They may
see different proxy setting. Therefore, if on the deployment server, it
will be necessary to access network through proxy server, you can consider
manually add code to specify the proxy for your HttpWebRequest component.

#HttpWebRequest.Proxy Property
http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.proxy(VS.
80).aspx

In addition, here is a good article introducing the proxy detection feature
in .net framework( include enhancement in 2.0):

#Proxy Detection
Take the Burden Off Users with Automatic Configuration in .NET
http://msdn.microsoft.com/msdnmag/issues/05/08/AutomaticProxyDetection/defau
lt.aspx

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

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.
Lee Wilson - 27 Jun 2007 09:44 GMT
Steven,

** Yes, the scenario is as described.

** Yes, the request code is executed in an ASP.NET web application in the
web page code.

** IIS is being used to serve to project.

I will attempt to use your suggestion and post any feedback. Cheers for the
help,

Lee Wilson
Steven Cheng[MSFT] - 28 Jun 2007 02:24 GMT
Thanks for your prompt response Lee,

Looking forward to further progress from you.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Lee Wilson - 28 Jun 2007 14:09 GMT
Steven,

To be honest, I do not feel like I am getting anywhere with this.

I have inserted the following code before using the GetRequestStream()
method:

request.Proxy = new WebProxy("http://ProxyUrl:ProxyPort/", true);
request.Proxy.Credentials = new NetworkCredential(studentLoginId,
studentPassword);

The problem is not resolved. I will persevere and look forward to your
reply.

Lee Wilson
Steven Cheng[MSFT] - 28 Jun 2007 16:34 GMT
Thanks for your reply,

Actually, I originally mean waiting for your test result.

So you've inserted the proxy supplying code but it still not working. So
far I can't quite get anything else other than the network connection
issue. I'm not sure whether you can run a desktop program on the deployment
server. If so, you can conside put the same code into a winform or console
application and run it on the deployment server under an interactive
account to see whether it works. Interactive user account may benifit from
some proxy client setting while service account usually not.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
   

This posting is provided "AS IS" with no warranties, and confers no rights.
Lee Wilson - 29 Jun 2007 12:12 GMT
Okay, a simple Windows application has been developed which will print
"Done!" if the request was successful, or any exceptions which might occur.

All findings are as follows:

** Web application
- Development box through IIS - Done!
- Deployment box through IIS - 502 (Bad Gateway).

** Windows application
- Development box - Done!
- Deployment box as a domain user with administrator rights - 502 (Bad
Gateway).
- Deployment box as a local administrator - Done!

The results are replicated when tested with other exchange mailboxes.

Lee Wilson
Steven Cheng[MSFT] - 02 Jul 2007 10:39 GMT
Thanks for your followup Lee,

It is a bit unexpected that domain user account won't work here(in winform
application),  so far I haven't any definite clues on this behavior. I
think there will need some further troublshooting against the exchange
server and the intermediate network communication. Following things maybe
required:

** network monitor log between the server and client
** if there is any proxy server(such as ISA ) between the server, client,
you may need to check the proxy server log to see what's the problem, is it
possible that proxy server deny the request.

In addition, based on the natural complexity of such troubleshooting
scenario, if this is an urgent issue, I suggest contact CSS for further
assistance due to the support limitation in newsgroup.

http://msdn.microsoft.com/subscriptions/support/default.aspx

Please feel free to post here if there is anything else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Lee Wilson - 26 Jul 2007 12:31 GMT
Just to let you know the following code solves the problem just after
instantiation the HttpWebRequest object:

request.Proxy = null;

Eh.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.