Partager via


ASMX: Event code: 3005 : InvalidOperationException : Request format is unrecognized for URL unexpectedly ending in '/URL'.

Issue Definition

ASMX web service hosted over IIS.

Intermittently we observe following error being logged in event viewer.

 

Error In Event viewer:

Event code: 3005 

Event message: An unhandled exception has occurred. 

Event time: 02/03/2015 13:10:11

Event time (UTC): 02/03/2015 16:10:11 

Event ID: c9d437b7eddc4478b6e01d89516d0da1 

Event sequence: 2270182 

Event occurrence: 2481 

Event detail code: 0  

Application information:     

Application domain: /LM/W3SVC/1/ROOT/MyApp-1-130697010076094227     

Trust level: Full Application Virtual Path: /MyApp     

Application Path: D:\InternetFiles\MyApp\     

Machine name: MYMACHINE  

Process information:     

Process ID: 5160     

Process name: w3wp.exe     

Account name: IIS APPPOOL\ASP.NET v4.0 Classic   

Exception Information:     

Exception type: InvalidOperationException     
Exception message: Request format is unrecognized for URL unexpectedly ending in '/MyURL'.

 at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)

 at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)

 at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)

 at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)

 at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

 at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Request information:     

Request URL: <XYZ.com/MyApp/MyURL.asmx/MyURL?param=123>

Request path: /MyApp/MyURL.asmx/MyURL      

User host address: 192.1.1.1     

 

Solution

After some in depth troubleshooting, we found the problem rooted inside the HttpContext object associated with the incoming request:

Context Info
================================
Address : 00000004800d64f8
Target/Dump Time : 3/16/2015 1:34:58 PM
Request Time : 3/16/2015 1:34:49 PM
Running time : 00:00:08
HttpContext.Items[]: 0000000480119d58

Request Info
================================
HEAD /MyApp/MyUrl.asmx <---------------------- PROBLME
Content Length : -1

Because of VERB as HEAD, we are unable to process the request and eventually end up in writing the event logs.

 

=============
Conclusion:
=============
Some clients like JavaScript and Office use HEAD to probe the resource before sending the request. .asmx is not meant to be used with HEAD so it throws an exception and logs in Event Viewer.

 

Solution:

To resolve we can change the handle for ScriptHandlerFactory to change verb from * (all) to GET,POST only. This lead to IIS returns 404 (not found) and NO error was logged to Event Viewer 

 ************** Original ***********************
 <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"/>
 <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
 </httpHandlers>
 <httpModules>
 <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
 </httpModules>
 </system.web> 

***********************************************
************** Modified ********************
 <httpHandlers>
 <remove verb="*" path="*.asmx"/>
 <add verb="GET,POST" 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"/>
 <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
 </httpHandlers>
 <httpModules>
 <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
 </httpModules>
 </system.web> 
*********************************************

 

Hope this help !

 

Saurabh Somani - blogs.msdn.com/b/saurabs/ 

Rodney Viana - blogs.msdn.com/b/rodneyviana/