8

We have a SSL configured website that hosts a WCF-service. The service's binding has crossDomainScriptAccessEnabled="true" and communication is serialized using JSON.

When we request this service from http it returns JSONP but when it is requested using HTTPS it returns just JSON. I need to have JSONP in either way, please help.

Current configuration is like this:

<webHttpBinding>
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>

<behaviors>
            <serviceBehaviors>
                <behavior name="JsonServiceBehaviors">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors><behavior name="webHttpBehavior">
                <webHttp />
            </behavior></endpointBehaviors>
</behaviors>

<services>
            <service name="Backend.CIService" behaviorConfiguration="JsonServiceBehaviors">
                <endpoint address="" binding="webHttpBinding" 
                          bindingConfiguration="webHttpBindingWithJsonP" contract="Backend.ICIService"
                          behaviorConfiguration="webHttpBehavior"/>
            </service></services>
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
Alex LaWay
  • 435
  • 4
  • 7

1 Answers1

19

What happens if you use this configuration:

<webHttpBinding>
  <binding name="jsonp" crossDomainScriptAccessEnabled="true" />
  <binding name="jsonpSsl" crossDomainScriptAccessEnabled="true">
    <security mode="Transport" />
  </binding>
</webHttpBinding>

<behaviors>
  <serviceBehaviors>
    <behavior name="JsonServiceBehaviors">
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webHttpBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

<services>
  <service name="Backend.CIService" behaviorConfiguration="JsonServiceBehaviors">
    <endpoint address="" binding="webHttpBinding" 
      bindingConfiguration="jsonp" contract="Backend.ICIService"
      behaviorConfiguration="webHttpBehavior"/>
    <endpoint address="" binding="webHttpBinding" 
      bindingConfiguration="jsonpSsl" contract="Backend.ICIService"
      behaviorConfiguration="webHttpBehavior"/>
  </service>
</services>

The problem is that if you want to call service over both HTTP and HTTPS you must provide two endpoints - one for HTTP and one for HTTPS.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • 1
    I've never been able to get http and https working at the same time before, even with multiple endpoints. I'm not sure what exactly I was doing wrong, but this is the least confusing (and most successful) wcf answer I've seen. In fact it makes sense :) Not only that, it's made my need for cross domain scripts redundant! Woohoo! :D – Radderz Apr 20 '15 at 00:42
  • For those new to WCF... the element needs to go inside a element. – JamesQMurphy Jul 07 '15 at 04:12
  • 1
    Ditto @Radderz - I dont understand why the internet is full of examples that are hard to follow. No idea why THIS example worked, where 20 other's didnt (and no doubt because I was doing something wrong), but I finally have my WCF service responding over http and https, and is RESTful as well to boot! – ewitkows Jun 29 '18 at 18:32