1

次の問題があります。

Silverlight 5 プロジェクトと wcf (iis/ホストされていた) プロジェクト (.net 4) があります。

wcf プロジェクトには、basicHttpBinding にバインドされた複数のサービスと、netMsmqBinding にバインドされた 1 つのサービスが含まれています。

このアプリには、ユーザーが 1 ユーザーあたり最大 30 ファイル、最大 10 ユーザーまでの Excel エクスポートを生成できるユース ケースが 1 つあります。これは長時間実行される操作で、ファイルごとに最大 3 分かかります。

最初、エクスポート サービスは httpBinded で、15 を超えるレポートを生成する要求があると失敗しました。そのため、タイムアウトを増やしました。これは明らかに問題の正しい解決策ではありませんでした。

そこで、キューを使用することにし、エクスポート サービスのバインドを basicHttpBinding から netMsmqBinding に変更しました。

ワークフローは次のとおりです。

Silverlight クライアントは、ReportsService の次のメソッドに対してすべてのファイルを要求します。

[SecurityTokenValidation]
    [ErrorLogging]
    public string GenerateTablesReport(List<MeasurementDescription> measurements)
    {
        if (measurements == null || measurements.Count.Equals(0))
        {
            throw new FaultException("Invalid argument.", new FaultCode(ErrorCodes.InvalidArgumentException));
        }

        //put on queue from here

        ExportsServiceClient exportsServiceClient = new ExportsServiceClient();

        exportsServiceClient.GenerateTablesReport(measurements.ToArray());

        return new Guid().ToString();
    }

上記の方法では、メッセージをさらにキューに入れて送信しています。必要なセキュリティ権限を持つ ExportsService という名前のプライベート トランザクション キューを作成しました。

これまでのところ、これは機能します。キューにメッセージが表示されます。

問題は、メッセージを読み取ろうとすると ExportsService が失敗し、すべてのメッセージが「再試行」フォルダーに入れられることです。

この 2 日間であらゆることを試しました。msmq がマシン上で動作しているかどうかを確認するためだけに、いくつかの簡単なおもちゃのプロジェクトを試してみました。

svclog で、この例外を見つけました。System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer (オブジェクトの状態)System.Messaging.MessageQueueException (0x80004005) で: リモート コンピューターを使用できません。System.Messaging.MessageQueue.GetPrivateQueuesByMachine (文字列 machineName) で

ExportsService は次のようになります。

public class ExportsService : IExportsService
{
    [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
    [SecurityTokenValidation]
    [ErrorLogging]
    public void GenerateTablesReport(List<MeasurementDescription> measurements)
    {
        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
        {
            if (measurements == null || measurements.Count.Equals(0))
            {
                throw new FaultException("Invalid argument.", new FaultCode(ErrorCodes.InvalidArgumentException));
            }

            BusinessFactory.ReportsManager.GenerateTablesReport(measurements);

            scope.Complete();
        }
    }
}

Web 構成の興味深いビットは次のようになります。

<client>
  <endpoint address="net.msmq://localhost/private/ExportsService"
    binding="netMsmqBinding" bindingConfiguration="NetMsmqBinding_IExportsService"
    contract="WCF.ExportsService.IExportsService" name="NetMsmqBinding_IExportsService" />
</client>

<behaviors>
  <endpointBehaviors>

    <behavior name="BatchingBehavior">
      <transactedBatching maxBatchSize="16"/>
    </behavior>

  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="foobar">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      <serviceThrottling maxConcurrentCalls="60"  maxConcurrentInstances="60"   maxConcurrentSessions="60" />
    </behavior>

    <behavior name="ThrottlingBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceThrottling maxConcurrentCalls="4"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>

  <basicHttpBinding>
    <binding name="defaultBasicHttpBinding" closeTimeout="00:10:00"
      openTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
    </binding>
  </basicHttpBinding>
  <netMsmqBinding>
    <binding name="defaultNetMsmqBinding">
      <security mode="None" />
    </binding>
    <binding name="NetMsmqBinding_IExportsService">
      <security mode="None" />
    </binding>
  </netMsmqBinding>

</bindings>

<services>

  <service behaviorConfiguration="ThrottlingBehavior" name="FLM.Web.Services.ExportsService">
    <endpoint address="net.msmq://localhost/private/ExportsService" binding="netMsmqBinding" bindingConfiguration="defaultNetMsmqBinding" behaviorConfiguration="BatchingBehavior" contract="FLM.Web.Services.IExportsService"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>

  <service behaviorConfiguration="foobar" name="FLM.Web.Services.ReportsService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding"  contract="FLM.Web.Services.IReportsService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
  <service behaviorConfiguration="foobar" name="FLM.Web.Services.SecurityService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding" contract="FLM.Web.Services.ISecurityService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
  <service behaviorConfiguration="foobar" name="FLM.Web.Services.OrderingService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding"  contract="FLM.Web.Services.IOrderingService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
  <service behaviorConfiguration="foobar" name="FLM.Web.Services.ReportConfigurationService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding"  contract="FLM.Web.Services.IReportConfigurationService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
  <service behaviorConfiguration="foobar" name="FLM.Web.Services.AdminService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding"  contract="FLM.Web.Services.IAdminService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

</services>

4

0 に答える 0