我创建了一个 WCF 服务,它监听私有 MSMQ 的作业。我限制了我的服务,使其一次只能处理一项工作(maxConcurrentInstances = 1)。我遇到的问题是,当提交两条消息并通过计算机管理控制台检查队列时,它是空的。我希望有一条待处理的消息。当我提交三条消息时,我会在 MSMQ 中看到一条待处理的消息。从阅读 MSDN 来看,看起来 ServiceHost 正在内存中保存下一个作业,直到当前作业完成,但我找不到关闭它的方法,以便它不会将消息保存在内存中。有谁知道一种方法可以使 ServiceHost 不会将待处理的消息保存在内存中并将其留在队列中?谢谢!
<configuration>
<system.serviceModel>
<services>
<service
name="MyService"
behaviorConfiguration="DefaultServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MyService/"/>
</baseAddresses>
</host>
<endpoint
address="net.msmq://localhost/private/MyService"
binding="netMsmqBinding" bindingConfiguration="MsmqBindingNoSecurity"
contract="IMyService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceThrottling
maxConcurrentCalls="1"
maxConcurrentSessions="1"
maxConcurrentInstances="1"
/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netMsmqBinding>
<binding name="MsmqBindingNoSecurity"
useActiveDirectory="false"
exactlyOnce="false">
<security mode="None">
<transport
msmqAuthenticationMode="None"/>
</security>
</binding>
</netMsmqBinding>
</bindings>
</system.serviceModel>
</configuration>