我有一个在 MSMQ 中创建私人消息的 WCF 服务。消息创建得很好,我可以看到我的客户端应用程序正在创建的消息。
我还有一个似乎运行良好的 MSMQ 侦听器服务。当我启动服务时,它似乎成功地“处理”了队列中的消息并且它们被删除了。但是,我的侦听器服务的实现似乎没有被执行。
我对 MSMQ 还很陌生,我不知道为什么要从队列中删除消息,以及为什么我的侦听器方法中的代码没有被执行。
以下是我的服务课程...
[ServiceContract(Namespace = ServiceConstants.NAMESPACE, Name = "IOrderService")]
public interface IOrderQueueProcessingService
{
[OperationContract(IsOneWay = true, Action = "*")]
void ProcessOrderQueue(MsmqMessage<string> message);
}
public abstract class OrderQueueProcessingServiceBase : ServiceBase, IOrderQueueProcessingService
{
#region CONSTRUCTORS
protected OrderQueueProcessingServiceBase() { }
protected OrderQueueProcessingServiceBase(List<EventRecord> existingList) : base(existingList) { }
#endregion //CONSTRUCTORS
#region IOrderQueueProcessingService Members
[OperationBehavior(TransactionScopeRequired = false, TransactionAutoComplete = true)]
public virtual void ProcessOrderQueue(MsmqMessage<string> message)
{
throw new NotImplementedException();
}
#endregion
}
public class OrderQueueProcessingService : OrderQueueProcessingServiceBase
{
#region Constructors
public OrderQueueProcessingService() {}
public OrderQueueProcessingService(List<EventRecord> existingList) : base(existingList) { }
#endregion
/// <summary>
/// Processes any Orders in the Orders Queue
/// </summary>
/// <param name="message"></param>
public override void ProcessOrderQueue(MsmqMessage<string> message)
{
var q = new MessageQueue(@".\private$\msmqdemo/submitorderservice.svc");
q.Send("hey");
/*
using (new Tracer("OrderQueueProcessingService"))
{
// add data context to work with.
using (var unitOfWork = new TLFDataContext())
{
var newOrderLines = new List<OrderLineDataContract>
{
new OrderLineDataContract
{
C = "test",
IC = "msw",
Qty = 1,
T = "volume" ,
ED = DateTime.UtcNow.AddDays(5)
}
};
var newOrder = new OrderDataContract
{
LIs = newOrderLines.AsEnumerable(),
PId = 9323,
POId = 8686,
S = "new"
};
var orderService = new OrderService();
var createdOrder = orderService.CreateOrder(null, null, newOrder);
//unitOfWork.SubmitUnitOfWork();
//return null;
}
}*/
}
}
我注释掉了我最终尝试执行的代码,并将其替换为一个简单的 MSMQ 消息发送,以进行测试。这似乎应该可以正常工作。任何帮助将不胜感激。
下面配置设置...
<service name="ServiceImplementation.OrderQueueProcessingService">
<host>
<baseAddresses>
<add baseAddress="https://localhost:9000/OrderQueueProcessingService.svc" />
</baseAddresses>
</host>
<endpoint address="net.msmq://localhost/private/testingqueue/OrderQueueProcessingService.svc" binding="netMsmqBinding" bindingConfiguration="MsmqBindingNonTransactionalNoSecurity" contract="IOrderQueueProcessingService" />
</service>