我有一個使用JSONP(在Azure中託管)的WCF服務。它通過HTTP完美工作,也就是說,如果它僅接收JSON,它僅返回JSON,並且如果它接收到JSONP則返回JSONP。但是,只要切換到HTTPS(僅在Azure中提供HTTPS端點),它將僅返回JSON,而不管該調用是JSON還是JSONP。我對HTTP配置爲:爲什麼我的WCF JSONP服務不能通過HTTPS返回JSONP
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true">
</standardEndpoint>
</webScriptEndpoint>
</standardEndpoints>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
而且在服務Global.asax文件我有:
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.Add(new ServiceRoute("DirectTvService", new WebScriptServiceHostFactory(), typeof(DirectTVService.DirectTvService)));
}
}
我想從HTTP更改爲HTTPS,所以我加
<security mode="Transport">
</security>
到標準Endpoint標籤,因此:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true">
<security mode="Transport">
</security>
</standardEndpoint>
</webScriptEndpoint>
</standardEndpoints>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
我改變我的IIS7從HTTP到HTTPS綁定。有了這樣的配置的服務工作如預期的JSON,但只爲JSONP請求返回JSON(響應不裹在回調函數
我的客戶端請求(在CoffeeScript中的一個例子)是:
$.ajax
url: callUrl
dataType: 'jsonp'
data:
username: $('#txtUsername').val()
password: $('#txtPassword').val()
success: (data) =>
$.unblockUI()
Application.processLoginData data
false
error: (d, msg, status) ->
$.unblockUI()
alert "There was a problem contacting the database. " + status
false
我的服務方法都裝飾有:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public LoginResponse LoginUser(String username, String password)
任何想法
庫爾特