Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET WebService
Hi,
 
I am trying to call a web service on my client's web server to retrieve XML data. I use HttpWebRequest to call the web service. In the response, I get data in text/html type as my request fails and the client web server is redirecting me to their general web page. I'm guessing that my request is ending up with 4XX error from the web server behaviour (redirect). The thing is that I can actually get the correct response if I just cut and paste the URI that I'm using to create the HttpWebRequest object directly to the browswer. It is failing when I call it from my ASP.Net code. I'm not sure what I'm missing as it is a very simple code. By the way, I'm not able to use the way of adding a reference of a web service to the project and using the web service as an object because of our client side reason, so I have to use HttpWebRequest.
 
Here is my code.
 
objRequest = HttpWebRequest.Create(strURI)
objRequest.Method = "GET"
objResponse = objRequest.GetResponse()
objReader = New StreamReader(objResponse.GetResponseStream())
strXML = objReader.ReadToEnd()
objXML = New XmlDocument()
objXML.LoadXml(strXML)
objXML.Save("C:\TEMP\Test.xml")
 
Thanks in advance.
Posted 12-Feb-13 8:23am
Comments
Marcus Kramer at 12-Feb-13 13:30pm
   
It sounds like the web service uses authentication. When you send it from your browser you are likely passing your credentials along. Your web server runs under a service account and as such, it will make the request without credentials unless you specify them.
Sandeep Mewara at 12-Feb-13 14:23pm
   
I agree with your thought. +5.
Meg Takahashi at 13-Feb-13 16:17pm
   
Hi Marcus,
Thanks for your comment. I tried the follwoing and it didn't fix.
 
objRequest.PreAuthenticate = True
objRequest.Credentials = CredentialCache.DefaultNetworkCredentials
 
Am I doing wrong?
Guirec Le Bars at 12-Feb-13 22:47pm
   
Could also be that you are behind a proxy. No problem within browser but you have to set the proxy details inside the code as well (or in the System.Net part of your web.config). Check here : http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx
Meg Takahashi at 13-Feb-13 16:20pm
   
Hi Cuirec,
Thanks for your comment. I will definitely try your suggestion!
Meg Takahashi at 14-Feb-13 15:10pm
   
Hi everyone,
Thanks for all your replies. I tried all I could do but nothing worked, and it turned out that the problem was from a totally different issue. Web service is secured by IP address and my request is rejected in that matter. Thanks you all for your help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100