2

WCF サービスからデータを取得して Web サイトに表示しようとしています。
通信は次のようになります:
Web サイト --> WCF サービス --> CRM サーバー --> WCF サービス --> Web サイト

今私の問題は、取得するデータが大きく、約5k行になる場合があることです。(そして私のホスト PC は RAM を使い果たします) 1 ~ 10 行を Web サイトにストリーミングし、次に次の行をストリーミングしたいと考えています。

私の ServiceContract は次のようになります。

public interface ICommunicationService
{    
    [OperationContract]
    IEnumerable<Row> GetCrmData(string view);

}

そして私の実装:

public IEnumerable<Row> GetCrmData(string view)
{
    var data = new DataFromCrm(view);
    return data.GetRows(MetaInformation);
}

GetRows メソッドは次のようになります: http://msdn.microsoft.com/en-us/library/gg327917.aspx foreach を除いて、Row クラスに値を入力し、結果を返します。(ページングとクッキングは無効になっています)。

foreach (var c in returnCollection.Entities)
{
    var row = new Row();
    row.RecordId = c.Attributes[ID].ToString();
    foreach (var info in metaInfo)
    {
        row.Cells.Add(c.Attributes[info.AttributeName]);
    }
    yield return row;
}

1.イールド リターンは正しく使用されていますか?

バインディング
WCF サービス:

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
  <service behaviorConfiguration="ServiceBehavior" 
           name="ComToCrmService.CommunicationService">
    <endpoint binding="basicHttpBinding" 
              bindingNamespace="http://localhost:9006/CommunicationService.svc" 
              contract="ComToCrmContracts.ICommunicationService" />
  </service>
</services>

WCF クライアント

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ICommunicationService" 
                 closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
                 maxBufferSize="65536" 
                 maxReceivedMessageSize="4294967294" 
                 messageEncoding="Text" 
                 textEncoding="utf-8" 
                 transferMode="Streamed" 
                 useDefaultWebProxy="true">
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint binding="basicHttpBinding" 
                bindingConfiguration="BasicHttpBinding_ICommunicationService" 
                contract="ComToCrmReference.ICommunicationService" 
                name="BasicHttpBinding_ICommunicationService"
                address="http://dev11.meta10.com:9007/WCFTestService/CommunicationService.svc" />
    </client>
  </system.serviceModel>

2. Are the bindings correct?

3. Is there a failure in my thinking? remember I'm trying to get 1-10 rows out of 5000 display them on the website, get the next 1-10 rows and so on.
there are only data no binary data or something similar.

4. is it even possible with just one request?

4

1 に答える 1

6

何よりもまず、WCF はオブジェクト指向ではなく、サービス指向のパラダイムにあることを覚えておいてください。WCF を取り巻く多くの誤解は、サービス呼び出しをまとめてオブジェクト指向の方法で提示する能力にあります。

IEnumerable<Row>サービスからを返すことができるという事実は、この例です。実際には、WCF はネットワークを介してサービス呼び出しの結果をシリアル化する必要があり (非常に具体的な実装)、クライアントのインターフェイスにキャストする必要があります。 .

したがって、必要なシーケンスの「遅延」評価を実行することはできません。最初の 10 個だけが必要な場合でも、結果セット全体をネットワーク経由で取得することになります。

WCF はストリーミング ( http://msdn.microsoft.com/en-us/library/ms733742.aspx ) をサポートしていますが、より簡単な方法は、必要なページ情報を示すためにサービス コントラクトにパラメーターを追加することです。

public interface ICommunicationService
{
    [OperationContract]
    Row[] GetCrmData(string view, int pageNumber, int pageSize);
}

この契約は、ステートレスなサービス指向のアプリケーションとより一致しており、大量のデータをシステムに渡すのではなく、必要なものだけを使用するべきであるという考えを尊重しています。

を配列に置き換えたことに注意してくださいIEnumerable<Row>。ネットワークを介してインターフェイスにプログラミングしているという印象を取り除きます。

于 2013-08-28T14:30:03.353 に答える