Wednesday, March 28, 2012

AJAX based Web service authentication issue

Hi, I have created a webservice for putting overlays on googlemap. I am using scriptmanager to generate java proxy class. Everything works as expected as long as I use localhost in the url e.g.http://localhost/test.aspx orhttp://localhost/map.asmx/js but if I use the actual domain name then it don't work anymore e.g.http://www.test.com/test.aspx orhttp://www.test.com/map.asmx/js. In case of IE7 i get script error 'test is undefined' and in case of Firefox, I get authentication failed. The result is same whether I run it on the server or on the client. I have tried every possible thing that I can think of. Environment is Win 2003 and IIS 6.0. Framework 2.0 is enabled in the web services entensions. I am using windows integrated authentication and anonymous access is also enable. I am new to ajax world and trying hard for last 2 days to solve this problem. Please help me. Thanks a lot

Hi,

Can you directly browse to http://www.test.com/map.asmx/js. and does that download the Script Proxy ?

Also , can you take a look at the IIS Logs to understand the behavior on the server when you browse to the page ?

Go to Start --> Run -->Type in "LogFiles"

In the folder that opens up , go inside W3SVC1.

Take a look at the File exmmddyy.log and paste the lines that havemap.asmx/js. here.


Thanks for quick response. When I directly browse to .../js in IE7, i get 500 internal error whereas in case of Firefox, it prompts to download a file and the contents of the file are: "{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}".

No such folder "W3SVC1" exists under LogFiles ... only following folders are present there "Cluster, HTTPERR, ShutDown" and in there I am not able to find anything related to my issue.

Please let me know what next I should do? Thanks


Hi,

HttpPost andHttpGet for webservices is disabled by default in ASP.net 2.0

See if you can find the following snippet in your web.config , if it doesnt exist, add it under the <System.Web> Tag

<webServices>
<protocols>
<add name="HttpSoap1.2"/>
<add name="HttpSoap"/>
<add name="HttpPost"/> // uncomment this
<add name="HttpGet"/> // uncomment this
<add name="HttpPostLocalhost"/>
<add name="Documentation"/>
</protocols>
<soapExtensionTypes>
</soapExtensionTypes>
<soapExtensionReflectorTypes>
</soapExtensionReflectorTypes>
<soapExtensionImporterTypes>
</soapExtensionImporterTypes>
<wsdlHelpGenerator href="http://links.10026.com/?link=DefaultWsdlHelpGenerator.aspx"/>
<serviceDescriptionFormatExtensionTypes>
</serviceDescriptionFormatExtensionTypes>
</webServices>

Hope this helps


Read this KB article about Protocols and web services

HOW TO: Limit the Web Services Protocols that a Server Permits

http://support.microsoft.com/?id=815150


Yes, it was not there and I copied it under system.web tag but the issue is still there. There is also an <httpHandles> tag under system.web. I am pasting the lines from my web.config related to ajax. May be it will give further clue. Please let me know if u see something wrong there or what should I do next. Thanks a lot.

--------

<configSections>
<sectionGroupname="system.web.extensions"type="System.Web.Configuration.SystemWebExtensionsSectionGroup,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionGroupname="scripting" type="System.Web.Configuration.ScriptingSectionGroup,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionname="scriptResourceHandler"type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="MachineToApplication" />
<sectionGroup name="webServices"type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionname="jsonSerialization"type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="Everywhere" />
<sectionname="profileService"type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="MachineToApplication" />

<section name="authenticationService"type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
<sectionGroup name="applicationSettings"type="System.Configuration.ApplicationSettingsGroup, System,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="wwwroot.Properties.Settings"type="System.Configuration.ClientSettingsSection, System,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"requirePermission="false" />
</sectionGroup>
</configSections>

<system.web>

<httpHandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false"type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
<add verb="*"path="*_AppService.axd" validate="false"type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
<addverb="GET,HEAD" path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false" />

</system.web>

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="ScriptModule" preCondition="integratedMode"type="System.Web.Handlers.ScriptModule, System.Web.Extensions,Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
<addname="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="ScriptResource" preCondition="integratedMode"verb="GET,HEAD" path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>

----------------


I have found the iis logfiles and the directory 'W3SVC1' ... this directory is present in another partition because of setting different path for logging from IIS console.

Below are the lines related to this webservice:

this is the line when called with the following url : http://localhost/WebServices/WSGoogleMaps.asmx

2007-02-22 17:06:54 127.0.0.1 GET /webservices/wsgooglemaps.asmx/js - 80 - 127.0.0.1 Mozilla/5.0+(Windows;+U;+Windows+NT+5.2;+en-US;+rv:1.8.1.1)+Gecko/20061204+Firefox/2.0.0.1 200 0 0

and this is the line when called with the following url: http://mytest.server.com/WebServices/WSGoogleMaps.asmx

2007-02-22 18:15:27 192.167.1.273 GET /WebServices/WSGoogleMaps.asmx/jsdebug - 80 - 132.136.112.84 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.1;+InfoPath.2;+.NET+CLR+2.0.50727;+.NET+CLR+1.1.4322) 500 0 0

I have tried it on the server itself as well. If I use domainname then it is giving 500 internal error in IE7 or authentication failed in Firefox. This is the line when called from the server itself using domain name:

2007-02-22 16:41:04 192.167.1.273 GET /WebServices/WSGoogleMaps.asmx/jsdebug - 80 - 192.167.1.273 Mozilla/5.0+(Windows;+U;+Windows+NT+5.2;+en-US;+rv:1.8.1.1)+Gecko/20061204+Firefox/2.0.0.1 500 0 0

I simply don't understand that how same code on the same machine works with localhost in the url but gives error when called with domain name in the url. I am totally lost. Please help me solve it ... I need to solve it urgently. Thanks.


Hi there,

We are experiencing the same issue that seems to do with the domain name causing the authentication error in some environments. Did you ever get a resolution to this issue?

No comments:

Post a Comment