title: Cordova Phonegap - Simple Jquery Call
body: <p>I can not make wcf calls.</p>
  
  <p>I'm using:</p>
  
  <ul>
  <li>wcf </li>
  <li>visual studio cordova</li>
  </ul>
  
  <p>Someone help me?</p>
  
  <p><strong>Interface definition</strong></p>
  
  <pre><code>[ServiceContract]
  public interface IService
  {
          [OperationContract]
          [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
          string GetAddNumbers(int a, int b);
  }
  </code></pre>
  
  <p><strong>Service</strong>, simple method that takes two parameters and returns a value</p>
  
  <pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
  public class Service : IService
  {
      public string GetAddNumbers(int a, int b)
      {
          return (a + b).ToString();
      }
  }
  </code></pre>
  
  <p><strong>Service Web Config</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5"/&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="ServiceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="EndpBehavior"&gt;
            &lt;enableWebScript/&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="ServiceBehavior" name="Service"&gt;
          &lt;endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="EndpBehavior" bindingConfiguration="crossdomain"/&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"&gt;
      &lt;/serviceHostingEnvironment&gt;
      &lt;bindings&gt;
        &lt;webHttpBinding&gt;
          &lt;binding name="crossdomain" crossDomainScriptAccessEnabled="true"/&gt;
        &lt;/webHttpBinding&gt;
      &lt;/bindings&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-Headers" value="Content-Type, Accept" /&gt;
          &lt;add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" /&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><strong>Cordova App</strong> - Using JQuery to call wcf</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link href="Content/jquery.mobile-1.4.5.min.css" rel="stylesheet" /&gt;
      &lt;script src="scripts/jquery-2.1.3.min.js"&gt;&lt;/script&gt;
      &lt;script src="scripts/jquery.mobile-1.4.5.min.js"&gt;&lt;/script&gt;
      &lt;script src="cordova.js"&gt;&lt;/script&gt;
      &lt;script&gt;
  
          //$.support.cors = true;
  
          document.addEventListener("deviceready", onDeviceReady, false);
  
          function onDeviceReady() {
  
              $("button").click(function () {
  
                  var params = { a: $("#first").val(), b: $("#second").val() };
  
                  $.ajax({
                      url: 'http://*******:***/Service.svc/GetAddNumbers',
                      data: params,
                      type: "GET",
                      dataType: "json",
                      success: function (data, status, xr) {
                          $("#results").html(data);
                      },
                      error: function (xr, msg, e) {
                          $("#results").html(msg);
                          alert(msg);
                      }
                  });
              });
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          &lt;input id="first" type="text" /&gt;
          &lt;input id="second" type="text" /&gt;
          &lt;button&gt;Call Wcf&lt;/button&gt;
          &lt;div id="results"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>