【发布时间】:2015-08-12 15:03:43
【问题描述】:
我已经设置了一个 Web 服务(.asmx 变体),当我打开自定义错误处理时遇到了问题;一切正常,自定义错误关闭。当我打开它们并进行相同的 Web 服务调用时,我会返回 405 状态并出现以下错误:
[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
我的 Web 服务声明如下,它通过 javascript 作为 POST 调用到 http://xxx/WebServices/TestService.asmx/MyMethod,正文中带有 param1=xyz。
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
}
}
}
为了完整起见,我在 Web.Config 中的声明如下:
<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>
在 Application_BeginRequest 全局函数中执行此操作后,我可以看到一切正常 - 我只是看不出哪里出了问题!我也直接去了 asmx 文件并通过生成的表单提交并收到相同的错误。
这已经过测试,并且在 IIS7 机器以及我的 IIS express 开发机器上做同样的事情。
【问题讨论】:
标签: c# .net web-services iis