使用SSL上的JSONP的WCF服务 [英] WCF service with JSONP over SSL

查看:141
本文介绍了使用SSL上的JSONP的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个配置了SSL的网站,可托管WCF服务.服务的绑定具有crossDomainScriptAccessEnabled="true",并且通信使用JSON进行序列化.

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

当我们从http请求此服务时,它返回JSONP,但是当使用HTTPS请求时,它仅返回JSON.无论哪种方式我都需要JSONP,请帮忙.

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.

当前配置如下:

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

推荐答案

如果使用此配置会发生什么:

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>

问题是,如果要同时通过HTTP和HTTPS调用服务,则必须提供两个端点-一个用于HTTP,另一个用于HTTPS.

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.

这篇关于使用SSL上的JSONP的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆