Web アプリケーションの Silverlight コードで使用される WCF サービスがあります。ASP.NET ルーティング機能を使用します。
private void RegisterRoutes()
{
var factory = new WebServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute("Service", factory, typeof(ServiceService)));
}
これは現在、本番環境で機能しています。
他のいくつかの環境では、例外が発生します
System.InvalidOperationException: WebHttpBinding をバインドするエンドポイントのスキーム http に一致するベース アドレスが見つかりませんでした。登録されているベース アドレス スキームは [https] です。
まったく同じコードを統合環境とトレーニング環境にデプロイしました。統合では機能しますが、トレーニングでは失敗します。どちらの環境も、同じバージョンの Windows Server 2008 R2 Enterprise と同じバージョンの IIS 7.5 を実行しています。どちらも IIS で同じバインドが構成されています (すべての IP アドレスでポート 443 と 80)。
コードをインストルメント化しましたが、動作すると http と https の両方がサービスで使用されていることがわかります。失敗すると、https のみが使用されます。web.config は、2 つのシステム間で同一です。
一般に、IIS アプリケーションでホストされるサービスでは、WCF が IIS のバインド情報を使用することを知っています。この場合、ASP.NET ルーティング機能が使用されています。
WCF は使用するベース アドレスをどのように決定しますか?
更新: web.config ファイルの抜粋を次に示します。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<diagnostics>
<endToEndTracing propagateActivity="true" activityTracing="true"
messageFlowTracing="true" />
</diagnostics>
<extensions>
<behaviorExtensions>
<add name="silverlightFaults" type="Services.SilverlightFaultBehavior, Services" />
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SilverlightRESTBehavior">
<webHttp helpEnabled="false" automaticFormatSelectionEnabled="false"
defaultOutgoingResponseFormat="Json" faultExceptionEnabled="false" />
<silverlightFaults />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="ServiceBehavior" name="Services.SpendAnalysisService">
<endpoint address="" behaviorConfiguration="SilverlightRESTBehavior"
binding="webHttpBinding" contract="Services.SpendAnalysisService" />
<host> <!-- Added: not in the original-->
<baseAddresses>
<add baseAddress="http://" />
<add baseAddress="https://" />
</baseAddresses>
</host>
</service>
</services>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="d" helpEnabled="false" defaultOutgoingResponseFormat="Json"
automaticFormatSelectionEnabled="false" faultExceptionEnabled="false" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
編集:
もう 1 つのヒント:「SSL が必要」は、トレーニング環境の IIS で設定され、統合環境でクリアされました。Training 環境でこれをクリアすると、サーバー側の例外が防止されます。現在、両方の環境の WCF ログは、http アドレスと https アドレスの両方が考慮されていることを示しています。
問題は、リクエストが https として到着したときに、なぜ WCF が http が必要だと考えるのかということです。