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, ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#11
| |||
| |||
| 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 |
|
#13
| |||
| |||
| Try unchecking Integrated Windows Authentication in your Directory Security settings. It worked for me. : ) |
|
#14
| |||
| |||
| 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 |
|
#15
| |||
| |||
| 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 |
|
#16
| |||
| |||
| 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! |
|
#17
| |||
| |||
| 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 |
|
#18
| |||
| |||
| 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? |
|
#19
| |||
| |||
| 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 |
|
#20
| |||
| |||
| 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
} |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |
Our Partners |