1

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)

何か案は?

カート

4

1 に答える 1

1

奇妙なことに、有効な解決策は、Azure 構成に HTTP エンドポイントと HTTPS エンドポイントの両方を用意することでしたが、私の WCF 構成ではエンドポイントを 1 つしか提供しませんでした。次の serviceModel 構成を使用しました。

  <system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
  <webScriptEndpoint>
    <standardEndpoint name="" crossDomainScriptAccessEnabled="true">
    </standardEndpoint>
  </webScriptEndpoint>
</standardEndpoints>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

そしてすべてがうまくいきました。Azure 構成で HTTP エンドポイントを削除するとすぐに、JSONP が機能しなくなり (JSON が返されるだけ)、追加するとすぐに

<security mode="Transport">
</security>

standardEndPoint に (HTTPS で行う必要があると予想されるように)、動作も停止します...

于 2012-10-04T22:53:42.853 に答える