我有以下问题:
我有一个 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(Object state)System.Messaging.MessageQueueException (0x80004005):远程计算机不可用。在 System.Messaging.MessageQueue.GetPrivateQueuesByMachine(字符串机器名)
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>