Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1- make sure you set <code>crossDomainScriptAccessEnabled="true"</code> in <code>webHttpBinding</code></p> <p>Config file should be like following</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation debug="true"/&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;bindings&gt; &lt;webHttpBinding&gt; &lt;binding name="crossDomain" crossDomainScriptAccessEnabled="true" /&gt; &lt;/webHttpBinding&gt; &lt;/bindings&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior&gt; &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --&gt; &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;httpProtocol&gt; &lt;customHeaders&gt; &lt;add name="Access-Control-Allow-Origin" value="*" /&gt; &lt;add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" /&gt; &lt;add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /&gt; &lt;add name="Access-Control-Max-Age" value="1728000" /&gt; &lt;/customHeaders&gt; &lt;/httpProtocol&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p>2- your method should decorated like following</p> <p>for get resquest :</p> <pre><code>[OperationContract] [WebGet(UriTemplate = "/Dowork/{name}/{action}", ResponseFormat = WebMessageFormat.Json)] CompositeType DoWork(string name, string action); </code></pre> <p>for post request :</p> <pre><code>[WebInvoke(UriTemplate = "/DoworkPOST/{name}", Method = "POST", ResponseFormat = WebMessageFormat.Json,RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] [OperationContract] CompositeType DoWorkPost(string name, string action1, string action2); </code></pre> <p>3-in java script you can access like following </p> <pre><code>//for get function testGet() { $.ajax({ url: 'http://www.yourhost.com/yourservicename.svc/DoWorkPost/azadeh1', success: function (data) { $("#result").html('Load was performed' + data); } }); } //for post var testobj = { action1: "cook", action2: "dance" }; function testPost() { $.ajax({ type: "POST", url: 'http://www.yourhost.com/yourservicename.svc/DoWorkPost/azadeh', data: JSON.stringify(testobj), crossDomain:true, contentType: "application/json; charset=utf-8", dataType: "json", processdata: false, success: function (data) { $("#result").html('Load was performed' + data); }, error: function(jqXHR, textStatus, errorThrown) { $("#result").text(textStatus); } }); } </code></pre> <p>4- check your svc file</p> <pre><code>&lt;%@ ServiceHost Language="C#" Debug="true" Service="namespace.servicename" CodeBehind="servicename.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%&gt; </code></pre>
    singulars
    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.
    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