JSONP (Azure でホストされている) を使用する WCF サービスがあります。HTTP で問題なく動作します。つまり、JSON のみを受信した場合は JSON のみを返し、JSONP を受信した場合は JSONP を返します。ただし、HTTPS (Azure で HTTPS エンドポイントのみを提供) に切り替えるとすぐに、呼び出しが JSON か JSONP かに関係なく、JSON のみが返されます。HTTP の私の構成は次のとおりです。
<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>
したがって、次のように standardEndpoint タグに追加されます。
<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)
何か案は?
カート