Call WebService - Request format is unrecognized for URL unexpectedly ending



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


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页