我们有一个配置了SSL的网站,可托管WCF服务。服务的绑定具有,crossDomainScriptAccessEnabled="true"并且通信使用JSON序列化。
crossDomainScriptAccessEnabled="true"
当我们从http请求此服务时,它返回JSONP,但是当使用HTTPS请求该服务时,它仅返回JSON。无论哪种方式我都需要JSONP,请帮忙。
当前配置是这样的:
<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>
如果使用此配置会发生什么:
<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>
问题是,如果要同时通过HTTP和HTTPS调用服务,则必须提供两个端点-一个端点用于HTTP,另一个端点用于HTTPS。