title: WCF Custom JSONP Binding and httpsTransport
body: <p>My question revolves around a WCF REST Service for IIS that responds with JSONP.  I took the classes in this solution: <a href="http://msdn.microsoft.com/en-us/library/cc716898.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/cc716898.aspx</a> and added them to mine.  Things were working fine on my developer workstation using impersonation with httpTransport but when I tried to move up to the development server I ran into some security issues.  These issues were solved using the configuration below and an App Pool identity user.  I also configuring the IIS metabase file for NTLM only authentication (we are using IIS 6 but will be IIS 7 soon, needs to work on both) as I don't have access to make an SPN. I believe the current configuration solved my security problems <strong>but in the process my JSONP response was downgraded to regualar JSON</strong>, this is the problem.  Here is the relevant configuration:</p>
  
  <pre><code>    &lt;services&gt;
          &lt;service name="IS.Core.Infrastructure.RESTRouter.Transactions" behaviorConfiguration=""&gt;
              &lt;endpoint address="" behaviorConfiguration="webHttp" binding="customBinding"
                bindingConfiguration="jsonpBinding" contract="IS.Core.Infrastructure.RESTRouter.ITransactions"&gt;
              &lt;/endpoint&gt;
          &lt;/service&gt;
  
          &lt;service name="IS.Core.Infrastructure.RESTRouter.Queue" behaviorConfiguration=""&gt;
              &lt;endpoint address="" behaviorConfiguration="webHttp"  binding="customBinding"
                  bindingConfiguration="jsonpBinding" contract="IS.Core.Infrastructure.RESTRouter.IQueue" /&gt;
          &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;behaviors&gt;
          &lt;endpointBehaviors&gt;
              &lt;behavior name="webHttp"&gt;
                  &lt;webHttp /&gt;
              &lt;/behavior&gt;
          &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
  
      &lt;bindings&gt;
          &lt;customBinding&gt;
              &lt;binding name="jsonpBinding"&gt;
                  &lt;jsonpMessageEncoding /&gt;
                  &lt;httpsTransport
                        manualAddressing="true"
                        authenticationScheme="Ntlm" /&gt;
              &lt;/binding&gt;
          &lt;/customBinding&gt;
      &lt;/bindings&gt;
  
      &lt;extensions&gt;
          &lt;bindingElementExtensions&gt;
              &lt;add name="jsonpMessageEncoding"
                type="IS.Core.Infrastructure.RESTRouter.JsonpBindingExtension, RESTRouter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
          &lt;/bindingElementExtensions&gt;
      &lt;/extensions&gt;
  </code></pre>
  
  <p>Here is one of the interface method definitions:</p>
  
  <pre><code>    [OperationContract]
      [WebGet(UriTemplate = "{ModelPath}/{ObjectTypeName}?callback={callback}", ResponseFormat = WebMessageFormat.Json)]
      [JSONPBehavior(callback = "callback")]
      JSONPXml NewObject(string ModelPath, string ObjectTypeName, string callback);
  </code></pre>
  
  <p>Here is its implementation:</p>
  
  <pre><code>    [OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
      public JSONPXml NewObject(string ModelPath, string ObjectTypeName, string callback) {
  
          int val = getEmployeeIdByNTUsername(OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name);
  
          JSONPXml jsp = null;
          EntityPluginReflectorClient client = null;
          try {
              client = new EntityPluginReflectorClient();
              string output = client.NewObject(ModelPath, ObjectTypeName);
              jsp = new JSONPXml() { xml = output };
          } catch (Exception e) {
              InfrastructureLog.WriteException(this, "NewObject", e);
              jsp = getExceptionResponse(e);
          }
          finally {
              client.Close();
          }
          return (jsp);
      }
  </code></pre>
  
  <p>and here is the data contract:</p>
  
  <pre><code>[DataContract()]
  public class JSONPXml {
      public JSONPXml() { }
      [DataMember]
      public string xml;
  }
  </code></pre>
  
  <p>Please let me know if more information is needed and thanks for looking into this.</p>