Monday, March 12, 2012

Web Services - Unauthorized

I am attempting to create my first web service. I am now stuck at the following error.

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

I believe I have included the necessary code for assistance. If anything else is needed please let me know and I will reply ASAP.

Test.asmx<%@dotnet.itags.org. WebService Language="VB" CodeBehind="~/App_Code/Test.vb"Class="Test" %>
/App_Code/Test.vbImports System.WebImports System.Web.ServicesImports System.Web.Services.Protocols<WebService( _Namespace:="http://serverName.dev.intranet/")> _Public Class TestInherits System.Web.Services.WebService <WebMethod()> _Public Function PI()As Double Return System.Math.PIEnd Function <WebMethod()> _Public Function HelloWorld()As String Return"Hello World"End FunctionEnd Class
Client.aspx.vb...Sub btn1_Click( _ByVal senderAs Object, _ByVal eAs EventArgs)Dim srvAs New intranet.dev.serverName.Test srv.Credentials = System.Net.CredentialCache.DefaultCredentials lblTest.Text = srv.PIEnd Sub...
 
web.config...<authentication mode="Windows"/><identity impersonate="false"/>...
 
Thank you for your help.

Update -

When I run this on the development server (http://serverName.dev.intranet) it fails. When I run it on my local machine (http://localhost:port/...) it works. I hope that helps pinpoint the problem.

Thank you again for all of your help.


Usually this error means that the client application is not sending any credentials or the credentials are wrong. But I think you are setting the credentials correctly in your btn1_Click event handler. Most likely the permissions on the folder where the web service is located are not properly setup for IUSR_xxx.

Can you provide a description of your serverName.dev.intranet environment? Is it a shared hosting plan? Do you have full access to a dedicated server? etc.


It is an shared hosting environment on a corporate intranet. I do not have full access to the server settings.

You are probably correct about the folder permissions. Without having access to the server how can I get this to work?


If you know a network username andpassword that is guaranteed to have permissions to that folder you can try using aNetworkCredential.

See if the following article helps:How to: Configure an XML Web Service for Windows Authentication


I have attempted the Network Credential option and it also did not work. I have read/write permissions so I assumed my credentials would work but that was incorrect.

I will try it on another server and see if that works.

0 comments:

Post a Comment