【问题标题】:Request format is unrecognized for URL unexpectedly endingURL 意外结束的请求格式无法识别
【发布时间】:2014-01-09 02:53:24
【问题描述】:

各位专家,我有问题

当我在本地机器上尝试我的网络服务时,它工作正常

但是在我上传它并在托管服务器上运行 windows server 2008 r2 asp.net 4.0

我收到类似这样的错误请求格式无法识别,因为 URL 意外以 /setmylocation 结尾

我尝试了这些解决方案

    <system.webServer>
            <handlers>
                <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </handlers>
        </system.webServer>


    <configuration>  
        <system.web>  
        <webservices>  
            <protocols>  
                <add name="HttpGet"></add>  
                <add name="HttpPost"></add>  
            </protocols>  
        </webservices>  
        </system.web>  
    </configuration>

and here is my client side code

    $.ajax({
                        type: "POST",
                        url: "locations.asmx/setmylocation",
                        data: "{proid: '" + proid + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            var urloc = response.d;

                            if (urloc[0].LATITUDE == '') {

                                initializemap(14.001424154457723, 121.1032415625, 7);

                            } else {
                                initializemap(urloc[0].LATITUDE, urloc[0].LONGITUDE, 10);


                            }

                        },
                        failure: function (response) {
                            alert(response.d);
                        }
                    }); 

我尝试了所有方法,但问题仍然存在,希望得到问题的答案

谢谢

上图显示其他web服务调用就好了

还有来自 elmah.axd 的错误

System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/setmylocation'.
   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.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

【问题讨论】:

  • 我想补充一点,另外 2 个对 Web 服务的调用运行顺利
  • 我放弃了 Web 服务功能,只传递了经纬度槽查询字符串,我发现它更容易
  • 我和我的愚蠢,我忘了创建必要的存储过程,被 Web 服务访问终于让它工作了

标签: asp.net web-services


【解决方案1】:

.NET 连接的 Web 服务支持 HTTP GET、HTTP POST 和 SOAP 协议。默认情况下,在 .NET Framework 1.0 中,所有三个协议都已启用。默认情况下,在 .NET Framework 1.1 中,HTTP GET 和 HTTP POST 都被禁用。这是出于安全原因。

<protocols>
    <add name="HttpSoap"/>
    <add name="HttpPost"/>
    <add name="HttpGet"/> 
    <add name="HttpPostLocalhost"/>
      <!-- Documentation enables the documentation/test pages -->
    <add name="Documentation"/>
</protocols>

SMALL BLOG

【讨论】:

    【解决方案2】:

    在我的情况下,我不相信除了 setmylocation 之外所有其他对 Web 服务的调用都很好,所以我怀疑这是否是 asp.net 安装中的问题以及 web.config 中缺少配置所以我所做的是在我的浏览器示例上执行 Web 服务 sample.com/webservice.asmx/setmylocation?id=1 然后它向我显示了错误

    所以如果有人读到这篇文章并且你遇到了同样的问题,我希望它可以帮助你

    【讨论】:

      猜你喜欢
      • 2011-11-02
      • 2011-07-24
      • 2011-09-21
      • 2011-12-28
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 2011-03-01
      • 2016-04-06
      相关资源
      最近更新 更多