1

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"));
4

2 に答える 2

1

ふざけないで!これがうまくいかなかった理由は、MSDN の「Silverlight でのネットワーク セキュリティ アクセス制限」というタイトルの記事でわかりました。

ソケット クラスの使用に関するもう 1 つの制限は、ネットワーク アプリケーションが接続できる宛先ポート範囲が 4502 ~ 4534 の範囲内にある必要があることです。」

ポート番号を 4505 に変更した後、Silverlight から要求を行った後、サーバー コードに到達しました。

于 2010-01-02T20:29:15.780 に答える
0

現在行っているのとまったく同じ方法で、コードを使用してエンドポイントを作成してみてください。ただし、クライアント側では、プロキシをそのように作成します。

CustomBinding binding = new CustomBinding(
                new PollingDuplexBindingElement(),
                new BinaryMessageEncodingBindingElement(),
                new HttpTransportBindingElement());


private IDashboardService _svc = new DashboardServiceClient(binding,
   new EndpointAddress("http://localhost:8732/DashboardService"));
于 2010-01-02T08:42:04.187 に答える