gpt4 book ai didi

c# - MSMQ,消息被放入队列并消失但从未被服务契约(Contract)接收

转载 作者:太空宇宙 更新时间:2023-11-03 13:57:35 42 4
gpt4 key购买 nike

我有一个本地专用队列。我在 MVC 应用程序中也有一个 WCF 服务,它使用 msmqIntegrationBinding 监听队列。问题在于,当消息排队时永远不会调用服务契约,但消息会在那一刻消失。邮件不在病毒队列中。这是我声明绑定(bind)到队列的配置部分:

<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>

这是契约(Contract):

[ServiceContract(Namespace = "http://localhost/SkruvWeb/Service")]
public interface IQueueMessageReceiver
{
[OperationContract(IsOneWay = true, Action = "*")]
void PutScrewInfoMessage(MsmqMessage<string> 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");
}
}

对于为什么消息消失但不调用服务有什么建议吗?

最佳答案

尝试使用 ServiceKnownType 属性修改您的服务契约(Contract):

[ServiceContract(Namespace = "http://localhost/SkruvWeb/Service")]
[ServiceKnownType(typeof(String))]
public interface IQueueMessageReceiver
{
[OperationContract(IsOneWay = true, Action = "*")]
void PutScrewInfoMessage(MsmqMessage<string> msg);
}

更新

如果您使用的是 MsmqIntegrationBinding,我假设您的队列客户端是 VB6 客户端之类的遗留应用程序?如果是这样,您将需要在服务绑定(bind)配置中指定序列化格式。例如:

  <msmqIntegrationBinding>
<binding name="MsmqBinding" serializationFormat="ActiveX">
<security mode="None" />
</binding>
</msmqIntegrationBinding>

记录了允许值 here .

关于c# - MSMQ,消息被放入队列并消失但从未被服务契约(Contract)接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11645131/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com