我有一个 MVC 应用程序,它有一个控制器,它的动作应该从队列 (msmq) 中的最新消息中公开数据。我在本地机器上添加了一个私人队列。我希望应用程序在添加消息时自动从队列接收消息。为此,我在已添加到应用程序的 WCF 服务上使用 msmqIntegrationBinding。然后,在合约中获取消息的方法我应该将消息保存在应用程序缓存中,以便在客户端请求最新数据时可以访问它。
我现在面临的挑战是,当我将消息添加到队列时,WCF 服务不会接收到它。我需要关于我可能做错的事情的指导或对我的方法的反馈。请帮忙。
以下是 WCF 服务的端点配置:
<bindings>
<msmqIntegrationBinding>
<binding name="MsmqBinding">
<security mode="None" />
</binding>
</msmqIntegrationBinding>
</bindings>
<services>
<service name="TestApp.Web.Service.QueueMessageReceiver">
<endpoint address="msmq.formatname:DIRECT=OS:.\private$\testsmessagequeue"
binding="msmqIntegrationBinding"
bindingConfiguration="MsmqBinding"
contract="TestApp.Web.Service.IQueueMessageReceiver" />
</service>
</services>
以下代码来自 QueueMessageReceiver.cs WCF 服务:
public class QueueMessageReceiver : IQueueMessageReceiver
{
private static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ScrewInfoModel));
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void PutScrewInfoMessage(System.ServiceModel.MsmqIntegration.MsmqMessage<System.Xml.XmlDocument> msg)
{
CacheScrewInfoModelFromScrewInfoXmlDoc(msg.Body);
}
private static void CacheScrewInfoModelFromScrewInfoXmlDoc(XmlNode screwInfoXmlDoc)
{
var reader = new StringReader(screwInfoXmlDoc.InnerXml);
var screwInfoModel = (ScrewInfoModel)Serializer.Deserialize(reader);
Common.Utils.CacheScrewInfo(screwInfoModel);
}
}
这是 WCF 的接口:
[ServiceContract]
public interface IQueueMessageReceiver
{
[OperationContract(IsOneWay = true, Action = "*")]
void PutScrewInfoMessage(MsmqMessage<XmlDocument> msg);
}