title: Calling WCF service from external domain
body: <p>I'm trying to call WCF service from external domain. It seems that I'm getting answer correct in Fiddler, but $ajax call return an error:</p>
  
  <blockquote>
    <p>Error: MyCallback was not called</p>
  </blockquote>
  
  <p>Sample application:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          $("#button1").click(function(){
              $.ajax({
                  url: "http://localhost:31492/LocationService.svc/GetLocation",
                  data: '{"id":"33"}',
                  dataType: "jsonp",
                  type: "GET",
                  timeout: 10000,
                  jsonpCallback: "MyCallback",
                  success: function (data, textStatus, jqXHR) {
                      $("#display").html(data);
                  },
                  error: function (jqXHR, textStatus, errorThrown) {    
                      alert(errorThrown);
                  },
                  complete: function (jqXHR, textStatus) {
                  }
              });
              function MyCallback(data) {
              alert(data);
          }
          });
      });
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h1&gt;Test&lt;/h1&gt;
      &lt;br&gt;&lt;br&gt;&lt;br&gt;
      &lt;div id="display"&gt;
      &lt;/div&gt;&lt;br&gt;
      &lt;button id="button1"&gt;Get External Content&lt;/button&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>EDIT: WCF Service Contract:</strong></p>
  
  <pre><code>[ServiceContract(SessionMode = SessionMode.NotAllowed)]
  public interface ILocationService
  {
      [OperationContract]
      [WebGet(ResponseFormat = WebMessageFormat.Json)]
      string GetLocation(int id);
  }
  </code></pre>