从msmq队列读取时出现WCF异常

时间:2014-10-03 08:23:46

标签: wcf iis msmq silverlight-5.0 was

我有以下问题:

我有一个silveright 5项目和wcf(iis /被托管)项目(.net 4)。

wcf项目包含多个basicHttpBinding绑定的服务和一个绑定netMsmqBinding的服务。

这个应用程序有一个用例,用户可以生成一些excel导出,每个用户最多30个文件,最多10个用户。 这是一个长时间运行的操作,每个文件最多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失败,所有这些邮件最终都在“重试”文件夹中。

我在最近两天尝试了一切。 我试着用一些简单的玩具项目来检查msmq的东西是否在机器上工作。

在svclog中我发现了这个异常。    在System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer(对象状态)System.Messaging.MessageQueueException(0x80004005):远程计算机不可用。    在System.Messaging.MessageQueue.GetPrivateQueuesByMachine(String 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>

0 个答案:

没有答案