我正在使用 MSMQ Web 服务从队列中读取数据并将其存储在数据库中。目前我正在使用 Visual Studio 2010 运行该服务(这是问题吗?)。代码片段如下。
合同
[ServiceContract]
public interface IService1
{
[OperationContract(IsOneWay = true,Action="*")]
void DOWork(MsmqMessage<Param> p);
}
执行
public class Service1:IService1
{
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void DoWork(Param p)
{
new Service1BL().DoWork(p);
}
}
配置
<service name="NameSpace.Service1" behaviorConfiguration="MSMQServiceBehavior">
<endpoint address="net.msmq://localhost/private/Service1" binding="netMsmqBinding" bindingConfiguration="PoisonBinding" contract="IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<behavior name="MSMQServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="True"/>
</behavior>
<netMsmqBinding>
<binding name="PoisonBinding" receiveRetryCount="1" maxRetryCycles="5" retryCycleDelay="00:00:05" receiveErrorHandling="Fault">
<security mode="None"/>
</binding>
</netMsmqBinding>
附加信息
我尝试过使用不同的队列名称。像 .\Private$\Service1 和 .\Private$\Service1.svc
- 消息队列、消息队列触发器、Net.Msmq Listner 适配器和 WAS 服务正在运行
- 我明确地将消息插入队列
--
MessageQueue queue = new MessageQueue(@".\private$\service1");
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
queue.Send(p, MessageQueueTransactionType.Single);
queue.Close();
scope.Complete();
}
原因是,我正在从另一个 Web 服务调用 MSMQ Web 服务。当我调用 MSMQ 服务时,它不是将消息插入队列,而是调用 MSMQ 服务。