title: WCF response in JSON instead of JSONP
body: <p>Allright, I'm using a WCF service to handle requests from my web app and respond with a JSONP format. I tried all the solutions I could find, studied the documentation (http://msdn.microsoft.com/en-us/library/ee834511.aspx#Y200) and the example project.</p>
  
  <p>The problem is the response object (json) does not get wrapped with the callback supplied in the URL.</p>
  
  <p>Request is like:</p>
  
  <pre><code>http://localhost/socialApi/socialApi.svc/api/login?callback=callback&amp;username=AAAAA&amp;password=BBBB
  </code></pre>
  
  <p><strong>Web.config looks like:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;trace enabled="true"/&gt;
      &lt;compilation debug="true" targetFramework="4.0"&gt;&lt;assemblies&gt;&lt;add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=*************" /&gt;&lt;/assemblies&gt;&lt;/compilation&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;
      &lt;services&gt;
        &lt;service name="RestService.socialApi"&gt;
          &lt;endpoint address="" binding="webHttpBinding" contract="RestService.IsocialApi" bindingConfiguration="webHttpBindingJsonP" behaviorConfiguration="webHttpBehavior"&gt;
          &lt;/endpoint&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="ServiceBehaviour"&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="true" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="webHttpBehavior" &gt;
            &lt;webHttp /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;
        &lt;webHttpBinding&gt;        
          &lt;binding name="webHttpBindingJsonP" crossDomainScriptAccessEnabled="true"/&gt;
        &lt;/webHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;!--&lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;--&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
     &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
    &lt;/system.webServer&gt;
    &lt;connectionStrings&gt;
      &lt;add name="AsrAppEntities" connectionString="myconstring**********" /&gt;
    &lt;/connectionStrings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>And my operationcontract:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.Text;
  using System.ServiceModel.Web;
  using System.IO;
  
  namespace socialApi
  {
      [ServiceContract]
      public interface IsocialApi
      {
          [OperationContract]
          [WebGet(
              ResponseFormat = WebMessageFormat.Json,
              BodyStyle = WebMessageBodyStyle.Bare,
              UriTemplate = "/api/login?username={username}&amp;password={password}")]
          JsonpAuthenticationResponse Login(string username, string password);
  
      }
  }
  </code></pre>
  
  <p><strong>The response is just normal json:</strong></p>
  
  <pre><code>{"Message":"unauthorized","Status":400,"Token":null}
  </code></pre>
  
  <p><strong>And I want:</strong></p>
  
  <pre><code>callbackfunction({"Message":"unauthorized","Status":400,"Token":null})
  </code></pre>
  
  <p>I think it has something to do with the Web.config, because when I modify the example and adjust the Web.config so it looks like mine the example doesn't function anymore. You would say I pinpointed the problem.. but no.</p>
  
  <p>To supply as much as information as possible, here is the working solution from the example:</p>
  
  <p><strong>Web.config:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!-- Copyright (c) Microsoft Corporation.  All rights reserved. --&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
      &lt;authentication mode="None" /&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
    &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;
      &lt;standardEndpoints&gt;
        &lt;webScriptEndpoint&gt;
          &lt;standardEndpoint name="" crossDomainScriptAccessEnabled="true"/&gt;
        &lt;/webScriptEndpoint&gt;
      &lt;/standardEndpoints&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p><strong>And the class:</strong></p>
  
  <pre><code>//----------------------------------------------------------------
  // Copyright (c) Microsoft Corporation.  All rights reserved.
  //----------------------------------------------------------------
  
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.ServiceModel.Activation;
  using System.ServiceModel.Web;
  
  namespace Microsoft.Samples.Jsonp
  {
      [DataContract]
      public class Customer
      {      
          [DataMember]
          public string Name;
  
          [DataMember]
          public string Address;
      }
  
  
      [ServiceContract(Namespace="JsonpAjaxService")]
      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
      public class CustomerService
      {
          [WebGet(ResponseFormat = WebMessageFormat.Json)]
          public Customer GetCustomer()
          {
             return new Customer() { Name="Bob", Address="1 Example Way"};
          }
      }
  }
  </code></pre>
  
  <p>The above example returns a jsonp object. This is the call from the example:</p>
  
  <pre><code>function makeCall() {
              var proxy = new JsonpAjaxService.CustomerService();
              proxy.set_enableJsonp(true);
              proxy.GetCustomer(onSuccess, onFail, null);
          }
  </code></pre>
  
  <p>proxy.set_enableJsonp(true); is maybe something I am missing in my call? But I can't add this in my call because I'm not calling the service from the same solution.</p>
  
  <p>So any idea's about what's causing the normal JSON response instead of the request JSONP?</p>