Silverlight 3 WCF クライアントで NotFound CommunicationException を受信する
-
22-09-2019 - |
質問
Silverlight 3 から WCF サービスを呼び出そうとすると、非常に役に立たない CommunicationException が発生します。例外のメッセージは「リモート サーバーがエラーを返しました:NotFound." それぞれの内部例外が同じメッセージをオウム返しします。この問題の原因となるセットアップに問題があるのでしょうか?
これが私のセットアップです。WCF サービスは、.NET 4.0 プラットフォームで実行される Windows サービスでホストされます。3 つのエンドポイントがあります。
- メイン エンドポイントは、pollingDuplexHttpBinding バインディングを使用し、アドレス「DashboardService」を持ちます。
- メタデータ交換エンドポイントは mexHttpBinding バインディングを使用し、アドレス「mex」を持ちます。
- エンドポイントを提供するポリシー (これはクロスドメイン呼び出しを許可する必要があります) は webHttpBinding バインディングを使用し、アドレス "" を持ちます。
system.serviceModel セクション全体は次のとおりです。
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplexHttpBinding" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement, System.ServiceModel.PollingDuplex, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="PolicyProviderBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="RoboTrader.TheFloor.DashboardService">
<endpoint address="" binding="webHttpBinding"
behaviorConfiguration="PolicyProviderBehavior"
contract="RoboTrader.DashboardService.IPolicyProvider"/>
<endpoint address="DashboardService" binding="pollingDuplexHttpBinding"
contract="RoboTrader.DashboardService.IDashboardService"/>
<endpoint address="DashboardService/mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Silverlight クライアント コードにサービス参照を追加しましたが、これは問題なく動作したようです。そして、クライアントは期待どおりにサービスのクロスドメイン ポリシーを取得します。ただし、メインの DashboardService メソッドを呼び出すと CommunicationException が発生し、サーバー側メソッドのブレークポイントに到達しません。サービス参照を追加して生成された Silverlight ClientConfig ファイルは次のとおりです。
<system.serviceModel>
<bindings>
<customBinding>
<binding name="PollingDuplexHttpBinding_IDashboardService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/DashboardService"
binding="customBinding"
bindingConfiguration="PollingDuplexHttpBinding_IDashboardService"
contract="Service.IDashboardService"
name="PollingDuplexHttpBinding_IDashboardService" />
</client>
</system.serviceModel>
この設定に問題はありますか、それともポーリング二重 HTTP バインディングを機能させるために追加で行う必要があることがありますか?それとも、問題が何であるかについて詳細な情報を入手する方法を少なくとも知っていますか?
編集:
代わりにコードを使用してクライアントとサーバーのバインディングを設定して、それが役立つかどうかを確認してみましたが、依然として同じ例外が発生します。サーバーコードは次のとおりです。
var dboardService = new DashboardService();
ServiceHost host = new ServiceHost(dboardService);
host.AddServiceEndpoint(
typeof(IDashboardService),
new CustomBinding(
new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()),
"DashboardService");
host.Open();
そして、クライアントのコードは次のとおりです。
private IDashboardService _svc = new DashboardServiceClient(
new PollingDuplexHttpBinding(),
new EndpointAddress("http://localhost:8732/DashboardService"));
編集2:
クライアントコードをこれに変更しようとしましたが、同じ問題が発生します。
private IDashboardService _svc = new DashboardServiceClient(
new CustomBinding(
new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()),
new EndpointAddress("http://localhost:8732/DashboardService"));
解決
ふざけないで!これが機能しない理由は、次のタイトルの MSDN 記事で見つかりました。 Silverlight のネットワーク セキュリティ アクセス制限:
ソケット クラスの使用に関する追加の制限の 1 つは、ネットワーク アプリケーションが接続できる宛先ポート範囲が 4502 ~ 4534 の範囲内である必要があることです。
ポート番号を 4505 に変更した後、Silverlight からリクエストを行った後、サーバー コードに到達しました。
他のヒント
コード、あなたは今それをやっているとまったく同じ方法を通じてエンドポイントを作成してみてください。 しかし、クライアント側でそのようなプロキシを作成します。
CustomBinding binding = new CustomBinding(
new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement());
private IDashboardService _svc = new DashboardServiceClient(binding,
new EndpointAddress("http://localhost:8732/DashboardService"));