Today I was trying to deploy a web service to good old SharePoint 2007 using STSDEV. While I know the proper way is to publish it to the ISAPI directory and update the approrpiate files in there to make it discoverable, for this project I just wanted it deployed to the LAYOUTS directory. After building my project and deploying everything to SharePoint, including my web service, I tried invoking my web service using the test harness that ASP.NET includes out of the box, but to my dismay I was greeted with the following error:
Request format is unrecognized for the URL unexpectedly ending in ‘/[WebMethodName]’.
After trying various actions including redeploying, restarting applications, servers, etc… I found out that the problem was not with SharePoint, not a URL rewrite problem as other bloggers had suggested that would rewrite my URL to lower case, nor was it an invalid web service. The problem was that the web.config that’s located in the %SharePoint Root%\LAYOUTS folders (12 Hive for the legacy folks) does not enable HttpPost or HttpGet. Because of this SharePoint is trying to serve the requested content up as if it was dynamic content living in SharePoint. The fix for this is easy. Just add the appropriate web service protocols to the web.config as shown below:
<system.web> <webServices> <protocols> <add name="HttpGet" /> <add name="HttpPost" /> </protocols> </webServices> </system.web>