JSON 応答を返す WCF サービスを作成しました。次に、関数をテストするための JavaScript コードを含む html ページを作成しました。サービスをステージング環境 (本番環境をエミュレートするために SSL を使用) に公開したとき、サービスの web.config ファイルを HTTPS 経由で動作するように更新する必要がありました。.svc エンドポイント (サービス ページは http と https の両方で表示されます) を直接参照したり、ブラウザーでサービスを呼び出したりすると (JSON 応答をダウンロードするように求められます)、すべて問題ないように見えますが、テスト ページをhttps バージョンを指定すると、「アクセスが拒否されました」というエラーが表示されます。
私の設定ファイルの servicemodel セクションのコードは次のとおりです。
<system.serviceModel>
<services>
<service name="Services.PromotionCodeGeneration" behaviorConfiguration="md">
<endpoint address="" binding="webHttpBinding" contract="Services.IPromotionCodeGeneration" behaviorConfiguration="webHttp" bindingConfiguration="webBindingSecure"/>
<endpoint address="" binding="webHttpBinding" contract="Services.IPromotionCodeGeneration" behaviorConfiguration="webHttp" bindingConfiguration="webBinding"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="md">
<serviceMetadata httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webBindingSecure">
<security mode="Transport"/>
</binding>
<binding name="webBinding">
<security mode="None"></security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
テストページのコードは次のとおりです。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script>
function api_test() {
var url = "https://test.mydomain.com/Services/PromotionCodeGeneration.svc/contest/useremail@mydomain.com";
var client = new XMLHttpRequest();
client.open("GET", url, false);
client.setRequestHeader("Authentication-Key", "LK589-JIJO-SHG9-0987-65TG-HJKU-Y$GH");
client.send();
var responseText = client.responseText;
var result = JSON.parse(responseText);
document.writeln("Id: " + result.Id + "<br/>");
document.writeln("Code: " + result.Code + "<br/>");
var expiryDate = "";
if (result.Expires != null){expiryDate = result.Expires;}
document.writeln("Expires: " + expiryDate + "<br/>");
document.writeln("Status: " + result.Status + "<br/>");
}
</script>
</head>
<body onload="api_test();">
</body>
</html>
私は2日間問題を調査してきました。ドメイン間で「XMLHttpRequest」メソッドを使用できないと多くの人が言っているのを見つけましたが、基本的な http では機能するので、信じがたいと思います。また、多くの異なるサービスモデル構成の提案を試しましたが、https 通信では機能しませんでした。https 経由で「アクセスが拒否されました」という応答を引き起こしている構成ページまたは呼び出しページに何かが表示されますか?
どんな助けでも大歓迎です。