C# MSMQ,消息被置于队列上并消失,但服务契约从未拾取消息
我有一个本地专用队列。我在MVC应用程序中还有一个WCF服务,它使用msmqIntegrationBinding侦听队列。问题在于,当消息排队时,服务契约从未被调用,但消息随后会消失。消息不在毒药队列中。下面是我声明队列绑定的配置部分:C# MSMQ,消息被置于队列上并消失,但服务契约从未拾取消息,c#,asp.net-mvc,wcf,msmq,msmqintegrationbinding,C#,Asp.net Mvc,Wcf,Msmq,Msmqintegrationbinding,我有一个本地专用队列。我在MVC应用程序中还有一个WCF服务,它使用msmqIntegrationBinding侦听队列。问题在于,当消息排队时,服务契约从未被调用,但消息随后会消失。消息不在毒药队列中。下面是我声明队列绑定的配置部分: <services> <service name="SkruvInfo.Web.Service.QueueMessageReceiver"> <endpoint address="msmq.formatname:DIRE
<services>
<service name="SkruvInfo.Web.Service.QueueMessageReceiver">
<endpoint address="msmq.formatname:DIRECT=OS:LEIA\private$\screwinfo_autotests_messagequeue"
binding="msmqIntegrationBinding"
bindingConfiguration="MsmqBinding"
contract="SkruvInfo.Web.Service.IQueueMessageReceiver" />
</service>
</services>
合同如下:
[ServiceContract(Namespace = "http://localhost/SkruvWeb/Service")]
public interface IQueueMessageReceiver
{
[OperationContract(IsOneWay = true, Action = "*")]
void PutScrewInfoMessage(MsmqMessage<string> msg);
}
[ServiceContract(命名空间=”http://localhost/SkruvWeb/Service")]
公共接口IQueueMessageReceiver
{
[运营合同(IsOneWay=true,Action=“*”)]
无效信息消息(MsmqMessage msg);
}
以下是服务中的方法:
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void PutScrewInfoMessage(System.ServiceModel.MsmqIntegration.MsmqMessage<string> msg)
{
log4net.Config.XmlConfigurator.Configure();
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
try
{
log.Debug("Message from queue: " + msg.Body.ToString(CultureInfo.InvariantCulture));
var xDoc = new XmlDocument();
xDoc.LoadXml(msg.Body);
CacheScrewInfoModelFromScrewInfoXmlDoc(xDoc);
}
catch (Exception e)
{
log.Error("Error parsing message from queue",e);
EventLog.WriteEntry("Application","Message error for screws");
}
}
[操作行为(TransactionScopeRequired=true,TransactionAutoComplete=true)]
public void PutScrewInfoMessage(System.ServiceModel.MsmqIntegration.MsmqMessage msg)
{
log4net.Config.XmlConfigurator.Configure();
var log=LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
尝试
{
log.Debug(“来自队列的消息:+msg.Body.ToString(CultureInfo.InvariantCulture));
var xDoc=new XmlDocument();
LoadXml(msg.Body);
CacheScrewInfoModelFromScrewInfoXmlDoc(xDoc);
}
捕获(例外e)
{
log.Error(“解析来自队列的消息时出错”,e);
WriteEntry(“应用程序”,“螺钉消息错误”);
}
}
关于消息为何会被拒绝但不会调用服务的任何建议?请尝试使用ServiceKnownType属性修改您的服务契约:
[ServiceContract(Namespace = "http://localhost/SkruvWeb/Service")]
[ServiceKnownType(typeof(String))]
public interface IQueueMessageReceiver
{
[OperationContract(IsOneWay = true, Action = "*")]
void PutScrewInfoMessage(MsmqMessage<string> msg);
}
[ServiceContract(命名空间=”http://localhost/SkruvWeb/Service")]
[ServiceKnownType(类型(字符串))]
公共接口IQueueMessageReceiver
{
[运营合同(IsOneWay=true,Action=“*”)]
无效信息消息(MsmqMessage msg);
}
更新
如果您使用的是MsmqIntegrationBinding,我假设您的队列客户端是一个类似VB6客户端的遗留应用程序?如果是这样,则需要在服务绑定配置中指定序列化格式。例如:
<msmqIntegrationBinding>
<binding name="MsmqBinding" serializationFormat="ActiveX">
<security mode="None" />
</binding>
</msmqIntegrationBinding>
允许的值已记录在案。根据我的经验,此行为是由序列化失败或消息太大(64KB是默认的最大消息大小)引起的。这会导致WCF无声地崩溃(是的,我也不理解这种设计选择),但仍然会从队列中删除消息 只要启用跟踪,您就会很快在WCF中看到导致这种情况的异常 将其添加到web.config(我就在下面)以进行粗略的跟踪设置。确保AppPool用户对日志记录文件夹具有写入权限
<system.diagnostics>
<trace autoflush="true" indentsize="4" />
<sources>
<source name="System.ServiceModel" switchValue="Warning">
<listeners>
<add name="textLogger" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="textLogger"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\logs\webbackend_wcf_log.txt" />
</system.diagnostics>
有趣的是,为什么要使用MsmqIntegrationBinding?您的队列客户端是否在旧平台上?我尝试了您建议的两种方法,但都不起作用。您使用集成绑定是有原因的吗?是的,这样服务可以在队列到达后台时自动接收消息。这对我来说不正确吗?你为什么不使用netMsmqBinding?这是MSMQ的标准WCF绑定。然后,您不再需要将MsmqMessage类型用作数据协定。MsmqIntergationBinding适用于非WCF客户端。msmq队列客户端使用的是什么技术平台?