Call WebService - Request format is unrecognized for URL unexpectedly ending

来源:互联网 发布:软件设计师 应用技术 编辑:程序博客网 时间:2024/04/29 17:25


I have jquery call an asp.net webservice.

 

$.ajax({
        timeout: 10000,
        type: "POST",
        url: "AgentService.asmx/GetAgentData",
        data: JSON.stringify({ agentId: agentId }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data, textStatus, xmlhttp) {

            if (data.d != null) {

                PopulateAgentData($popup, data.d);
            }
        },
        error: function (xmlhttp, errorMessage, exceptionObject) {

            HandlePopupError($popup, xmlhttp, errorMessage, exceptionObject);
        }
    });


Got following error

Request format is unrecognized for URL unexpectedly ending in /GetAgentData


I saw solution on internet

The solution in previous versions is to add this to the web.config for the protocols needed (typically omitting HttpGet for production):
<system.web>
  <webServices>
    <protocols>
      <add name="HttpGet" />
      <add name="HttpPost" />
      <add name="HttpSoap" />
    </protocols>
  </webServices>
</system.web>


I changed it.


Then, I got another exception:
System.InvalidOperationException: Request format is invalid: application/json; charset=UTF-8.
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()


Finally,

I solved it ending up running this command...
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis.exe -i
Note that you will need your command prompt in Administrator mode for it to work.


Then, IISReset  /restart

Then, reboot Windows


0 0