2011-03-04 23 views
7

Tenemos un sitio web configurado SSL que aloja un servicio WCF. El enlace del servicio tiene crossDomainScriptAccessEnabled="true" y la comunicación se serializa usando JSON.Servicio WCF con JSONP sobre SSL

Cuando solicitamos este servicio desde http, devuelve JSONP pero cuando se solicita mediante HTTPS, devuelve solo JSON. Necesito tener JSONP de cualquier manera, por favor ayuda.

configuración actual es la siguiente:

<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> 

Respuesta

17

¿Qué ocurre si se utiliza esta configuración:

<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> 

El problema es que si usted desea llamar servicio a través de HTTP y HTTPS debe proporcionar dos puntos finales: uno para HTTP y otro para HTTPS.

+0

¡Eso funcionó! ¡Un millón de gracias! –

+0

Nunca antes pude hacer que http y https funcionen al mismo tiempo, incluso con múltiples puntos finales. No estoy seguro de exactamente qué estaba haciendo mal, pero esta es la respuesta al wcf menos confusa (y más exitosa) que he visto. De hecho, tiene sentido :) ¡No solo eso, ha hecho que mi necesidad de scripts de dominios cruzados sea redundante! Woohoo! : D – Radderz

+0

Para los nuevos en WCF ... el elemento debe ir dentro de un elemento . – JamesQMurphy

Cuestiones relacionadas