IT Community - Software Programming, Web Development and Technical Support

HTTP Web Response Exception - I cant able to trap.

This is a discussion on HTTP Web Response Exception - I cant able to trap. within the Windows Mobile forums, part of the Mobile Software Development category; Hi all, I created 2 web services with VB.NET. When I test them in the automatically-generated aspx page, ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Mobile Software Development > Windows Mobile

Register FAQ Members List Calendar Mark Forums Read

Reply
 
Thread Tools Display Modes
  #11  
Old 08-30-2007, 09:37 AM
theone theone is offline
D-Web Sr.Programmer
 
Join Date: Jun 2007
Posts: 129
theone is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

Hi all,

I created 2 web services with VB.NET. When I test them in the
automatically-generated aspx page, there's no problem.

However, when I try to call them from a program, I get the following error:
The request failed with HTTP status 401: Access Denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request failed with HTTP
status 401: Access Denied.
--
When I turn on the trace I get this info:
Line 69:
System.Web.Services.Protocols.SoapDocumentMethodAt tribute("http://tempuri.or
g/BrowseDestinations",
Use:=System.Web.Services.Description.SoapBindingUs e.Literal,
parameterstyle:=system.web.services.protocols.soap parameterstyle.wrapped)>
_
Line 70: Public Function BrowseDestinations(ByVal StartDate As
String, ByVal EndDate As String, ByVal Categories As String) As
System.Data.DataSet
-->Line 71: Dim results() As Object =
Me.Invoke("BrowseDestinations", New Object() {StartDate,
EndDate,Categories})
Line 72: Return CType(results(0),System.Data.DataSet)
Line 73: End Function
--
The Line 71 raise the authentication error. This piece of code corresponds
to the proxy that VS.NET generates for the web service.

As you can see this is a security error caused by the automatically-generated
proxy and to be honest with you people, I
would be needing the 'Complete Idiot Guide' to solve it as I'm a newbie when
it comes to set access permitions in Windows 2000.

I have both anonymous access and integrated Windows auth checked for the
web directory hosting my web services.

Do i have to change wy config.web or anything like that?

Thanks in advance for any help
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12  
Old 08-30-2007, 09:42 AM
raja raja is offline
D-Web Trainee
 
Join Date: May 2007
Posts: 34
raja is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

I have the exact same problem! I was just doing the walkthrough (Accessing
A Web Service).
__________________
Raja. Myblog
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13  
Old 08-30-2007, 09:42 AM
theone theone is offline
D-Web Sr.Programmer
 
Join Date: Jun 2007
Posts: 129
theone is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

Try unchecking Integrated Windows Authentication in your Directory Security
settings. It worked for me. : )
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14  
Old 08-30-2007, 09:44 AM
suresh suresh is offline
D-Web Trainee
 
Join Date: Apr 2007
Posts: 20
suresh is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

I have exactly the same problem. I receive the 401 http error while doing
the walkthrough "Accessing an XML Web Servive using visual Basic or Visual
C#" (I did it with C#).

I tried to uncheck the "Integrated Windows Authentication" option in IIS
but it didn't work!


Here is the error I received from the Web Service:

Server Error in '/TempConvertClient2' Application.
--------------------------------------------------------------------------------

The request failed with HTTP status 401: Access Denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Net.WebException: The request failed with HTTP
status 401: Access Denied.

Source Error:


Line 35: [System.Web.Services.Protocols.SoapDocumentMethodAt tribute("http://Walkthrough/XmlWebServices/ConvertTemperature",
RequestNamespace="http://Walkthrough/XmlWebServices/", ResponseNamespace="http://Walkthrough/XmlWebServices/",
Use=System.Web.Services.Description.SoapBindingUse .Literal, ParameterStyle=System.Web.Services.Protocols.SoapP arameterStyle.Wrapped)]
Line 36: public System.Double ConvertTemperature(System.Double dFahrenheit)
{
Line 37: object[] results = this.Invoke("ConvertTemperature",
new object[] {
Line 38: dFahrenheit});
Line 39: return ((System.Double)(results[0]));


Source File: c:\inetpub\wwwroot\TempConvertClient2\Web References\ConvertSvc\Reference.cs
Line: 37

Stack Trace:


[WebException: The request failed with HTTP status 401: Access Denied.]
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream) +1174
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String methodName,
Object[] parameters) +216
TempConvertClient2.ConvertSvc.Service1.ConvertTemp erature(Double dFahrenheit)
in c:\inetpub\wwwroot\TempConvertClient2\Web References\ConvertSvc\Reference.cs:37
TempConvertClient2.WebForm1.Button1_Click(Object sender, EventArgs e)
in c:\inetpub\wwwroot\tempconvertclient2\webform1.asp x.cs:54
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(St ring
eventArgument) +58
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl,
String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15  
Old 08-30-2007, 09:46 AM
raja raja is offline
D-Web Trainee
 
Join Date: May 2007
Posts: 34
raja is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

You need to set the Credentials property of your service. To pass the
system credentials for the current security context, you can use
CredentialCache.DefaultCredentials.

For a service named SimpleService, it would look something like this:

[C#]
SimpleService ss = new SimpleService();
ss.Credentials = System.Net.CredentialCache.DefaultCredentials;
__________________
Raja. Myblog
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16  
Old 08-30-2007, 09:47 AM
theone theone is offline
D-Web Sr.Programmer
 
Join Date: Jun 2007
Posts: 129
theone is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

The call to System.Net.CredentialCache.GetCredential by the underlying web
services code will get a null w/o setting the value described below. That
being the case, does anyone know why in every web service example I've seen
this is never mentioned? Adding it works for both WinForm and ASP.NET as
seems to be required in each. Anyone have any background why this is never
mentioned since this is so critical to making web service calls work.

Thanks!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17  
Old 08-30-2007, 09:52 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Default Re: HTTP Web Response Exception - Time Out Error

I have code as follows -

href = "URL"

// Create a request for the URL.

WebRequest request = WebRequest.Create(href);

//Set the USerAgent

((HttpWebRequest)request).UserAgent = "msie";

// Get the response.

WebResponse response = request.GetResponse();



Sometimes the code "WebResponse response = request.GetResponse();" is giving time out error.



Please let me know how can I handle this situation.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18  
Old 08-30-2007, 09:54 AM
santhakumar santhakumar is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 928
santhakumar is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

Catch the exception



It would be more useful to see a complete program. It could be a programming error, or maybe the connection to the remote site is really timing out.



Are you disposing all WebResponse objects?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19  
Old 08-30-2007, 09:55 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Default Re: HTTP Web Response Exception - I cant able to trap.

This the modified code -



I have chnaged the code still also I am getting the error

// Create a request for the URL.

WebRequest request = WebRequest.Create("URL");

//Add the User Agent

((HttpWebRequest)request).UserAgent = "msie"

//Time out

((HttpWebRequest)request).Timeout = 600000;

//Time out

((HttpWebRequest)request).ReadWriteTimeout = 600000;

//set alive = true

((HttpWebRequest)request).KeepAlive = true;

//auto redirect = true

((HttpWebRequest)request).AllowAutoRedirect = true;

// Get the response.

WebResponse response = request.GetResponse();



I am getting the error in the line - "WebResponse response = request.GetResponse();"







Full program goes as follows -



XmlTextReader xmlTextReader = null;

// Create a request for the URL.

WebRequest request = WebRequest.Create(href);

//Set the USerAgent

((HttpWebRequest)request).UserAgent = ConfigurationSettings.AppSettings["USER_AGENT"].ToString();

//Time out

((HttpWebRequest)request).Timeout = Convert.ToInt32(ConfigurationSettings.AppSettings["URL_TIME_OUT"].ToString());

//Time out

((HttpWebRequest)request).ReadWriteTimeout = Convert.ToInt32(ConfigurationSettings.AppSettings["URL_TIME_OUT"].ToString());

//set alive = true

((HttpWebRequest)request).KeepAlive = true;

//auto redirect = true

((HttpWebRequest)request).AllowAutoRedirect = true;

// Get the response.

WebResponse response = request.GetResponse();

// Get the stream containing content returned by the server.

Stream dataStream = response.GetResponseStream();

//XmlTextReader

xmlTextReader = new XmlTextReader(dataStream);
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20  
Old 08-30-2007, 09:56 AM
santhakumar santhakumar is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 928
santhakumar is on a distinguished road
Thumbs up Re: HTTP Web Response Exception - I cant able to trap.

That's just more code, not a program—is that code executed in a loop, is there any exception handling, etc.?



At least, make sure to wrap your code that uses the WebResponse and the response Stream in a C# using block:

Code:
using (WebResponse response = request.GetResponse())

using (Stream responseStream = response.GetResponseStream())

{

    // Read from responseStream

}
Note that if this is all you need to do from a networking perspective, you're better of using System.Net.WebClient, as it shields you from the chores of managing and disposing responses, streams etc.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting keyboard response in php code sip PHP Programming 1 01-07-2008 12:22 AM
WebException, HTTP 404 ,the request failed with HTTP status 404: Not Found kingmaker ASP and ASP.NET Programming 2 08-29-2007 05:19 AM
If I use Response.Redirect in try block exception occurred in c#, Why? kingmaker C# Programming 1 07-19-2007 03:51 AM
How can I invoke another program or command and trap its output in C? Sabari C and C++ Programming 1 07-17-2007 03:01 AM
Performance on Web Response Times Jeyaseelansarc PHP Programming 0 05-18-2007 09:37 PM


All times are GMT -7. The time now is 12:36 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
Stamford Dentist | Euro Millions Lottery | Tech Support Services

SEO by vBSEO 3.0.0