Note that there are some explanatory texts on larger screens.

plurals
  1. POStatus code 405 for Restful Service call from jquery
    primarykey
    data
    text
    <p>I have created a restful service and trying to call it from webpage. but i am getting <strong>error code 405.</strong></p> <p><em><strong>the same rest service call works fine with soap UI</em></strong></p> <p>below are the details of wevservice and the jquery call</p> <p><strong>webservice api</strong></p> <blockquote> <p>[OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, UriTemplate = "PostMethodWithCustomerArray")] List PostMethodWithCustomerArray(List dataStrings);</p> </blockquote> <p><strong>Webservice code</strong></p> <pre><code> public List&lt;CustomerWithArray&gt; PostMethodWithCustomerArray(List&lt;CustomerWithArray&gt; dataStrings) { return dataStrings; } </code></pre> <p><strong>ajax call</strong></p> <pre><code>var UrlPostMethodWithCustomerArray = "http://localhost:29745/RESTfulService.svc/PostMethodWithCustomerArray"; var customerWithArray = [{ "Name": "Dipak Godbole", "Age": "27", "HumanType": "1", "strArray": ["11", "22"] }, { "Name": "Madan Chapa", "Age": "19", "HumanType": "3", "strArray": ["111", "222"] }, { "Name": "Raju Rohida", "Age": "55", "HumanType": "2", "strArray": ["1111", "2222"] }]; $(document).ready(function () { $.ajax({ cache: false, type: "POST", //GET or POST or PUT or DELETE verb url: UrlPostMethodWithparam, // Location of the service data: JSON.stringify(customerWithArray), dataType: "json", //Expected data format from server contentType: "application/json; charset=utf-8", success: function (msg) {//On Successfull service call $.each(msg, function (index, item) { alert(item.Name + item.HumanType); }); //alert(msg); }, error: ServiceFailed// When Service call fails }); }); </code></pre> <p><strong>Web Config sections</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;appSettings&gt; &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt; &lt;/appSettings&gt; &lt;system.web&gt; &lt;compilation debug="true" targetFramework="4.5" /&gt; &lt;httpRuntime targetFramework="4.5"/&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="TrialRESTService.RESTfulService" behaviorConfiguration="svcbehaviour"&gt; &lt;endpoint address="" binding="webHttpBinding" contract="TrialRESTService.IRESTfulService"/&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="svcbehaviour"&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior&gt; &lt;webHttp /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. --&gt; &lt;directoryBrowse enabled="true"/&gt; &lt;httpProtocol&gt; &lt;customHeaders&gt; &lt;add name="Access-Control-Allow-Origin" value="*" /&gt; &lt;add name="Access-Control-Allow-Headers" value="Content-Type" /&gt; &lt;add name="Access-Control-Allow-Methods" value="POST,GET"/&gt; &lt;/customHeaders&gt; &lt;/httpProtocol&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p>any help on this????</p> <p><strong>Error using Google crome developer tools</strong></p> <pre><code> OPTIONS http://localhost:29745/RESTfulService.svc/PostMethodWithCustomerArray 405 (Method Not Allowed) jquery-1.8.2.min.js:19 XMLHttpRequest cannot load http://localhost:29745/RESTfulService.svc/PostMethodWithCustomerArray. Invalid HTTP status code 405 Default.aspx:1 </code></pre>
    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