I've set up a web service (of the .asmx variety) and have ran into an issue when I turn on custom error handling; everything is working fine with custom errors off. When I turn them on and I make the same web service call I get returned a 405 status with the below error:
[HttpException (0x80004005): Request format is unrecognized.]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +489467
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +120
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +346
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
My web service declaration is as follows and it's being called through javascript as a POST to http://xxx/WebServices/TestService.asmx/MyMethod with param1=xyz in the body.
namespace Website.WebServices
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class TestService : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public void MyMethod(string param1)
{
//...Do some important stuff
}
}
}
For completeness my declaration in the Web.Config is below:
<system.webServer>
...
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1"/>
<error statusCode="404" path="/Error404.aspx" responseMode="ExecuteURL"/>
<remove statusCode="500" subStatusCode="-1"/>
<error statusCode="500" path="/Error.aspx" responseMode="ExecuteURL"/>
</httpErrors>
...
</system.webServer>
Following this through in the Application_BeginRequest global function I can see that everything is coming in fine - I just can't see where it could be going wrong! I've also gone directly to the asmx file and submitted via the generated form and receive the same error.
This has been tested, and is doing the same thing, on an IIS7 machine as well as my IIS express dev machine.