Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery Ajax call to C# Web Service Error
    primarykey
    data
    text
    <p>I am trying to make an AJAX call using jQuery to a C# Web Service located under the same website. No matter what I find/try, I keep on receiving a 500 error as such:</p> <pre><code>Request format is unrecognized for URL unexpectedly ending in '/MyTest'. </code></pre> <p><strong>jQuery AJAX call from web page</strong></p> <pre><code> $.ajax({ type: "POST", url: 'http://172.1.1.10/MYService/MyService.asmx/MyTest', data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { alert(data); }, error: function (data, errorThrown) { alert("Fail"); alert(errorThrown); } }); </code></pre> <p><strong>Web Service (MyService.asmx) Code Behind</strong></p> <pre><code>[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string MyTest() { return "Hello World"; } </code></pre> <p>and yes I have the following uncommented at the top:</p> <pre><code>[System.Web.Script.Services.ScriptService] </code></pre> <p>When I try to load my web page, I get the alert window saying "Fail". This is when I receive the 500 error (see top of post).</p> <p>Too many people suggested adding this to the web service's web.config:</p> <p><strong>Web Service (Web.config)</strong></p> <pre><code>&lt;configuration&gt; &lt;system.web&gt; &lt;webServices&gt; &lt;protocols&gt; &lt;add name="HttpGet"/&gt; &lt;add name="HttpPost"/&gt; &lt;/protocols&gt; &lt;/webServices&gt; &lt;/system.web&gt; &lt;/configuration&gt; </code></pre> <p>Upon adding this, I can hit the local machine with this address: </p> <pre><code>http://172.1.1.10/MYService/MyService.asmx/MyTest </code></pre> <p>and I get the proper response of "Hello World". Prior to adding this I would get the same 500 Error message locally.</p> <p>Both the web service and web site are setup on the same IIS instance, each as its own application, under the same web site in IIS. I know it is not a cross-domain issue because I am not getting the 503 error that you'd typically receive if this were true, nor am I getting the 404 error of File Not Found.</p> <p>I've scoured the web and cannot seem to find a resolution to this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload