简体   繁体   English

MSMQ,消息被放入队列中并消失,但从未被服务合同接收

[英]MSMQ, Message is put on queue and disapears but is never picked up by service contract

I have a local private queue. 我有一个本地私人队列。 I also have a WCF-service inside an MVC-application that listens to the queue using msmqIntegrationBinding. 我还在MVC应用程序内部有一个WCF服务,该服务使用msmqIntegrationBinding侦听队列。 The problem is that the service contract is never invoked when a message is queued but the message disapears the moment after. 问题在于,当消息排队时,永远不会调用服务协定,但此后消息会消失。 The message is not in the poison queue. 该消息不在中毒队列中。 Here is the config-part where i declare the binding to the queue: 这是配置部分,在这里我声明对队列的绑定:

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

And here is the contract: 这是合同:

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

And here is the method in the service: 这是服务中的方法:

    [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");
        }
    }

Any suggestions to why the message disapears but does not invoke the service? 关于为什么该消息消失但不调用该服务的任何建议?

Try to modify your service contract with ServiceKnownType attribute: 尝试使用ServiceKnownType属性修改服务合同:

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

UPDATE UPDATE

If you are using MsmqIntegrationBinding I am assuming your queue client is a legacy application like a VB6 client? 如果您使用的是MsmqIntegrationBinding,我假设您的队列客户端是像VB6客户端这样的旧应用程序? If so you will need to specify the serialization format in your service binding configuration. 如果是这样,您将需要在服务绑定配置中指定序列化格式。 For example: 例如:

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

Permissable values are documented here . 允许值记录在此处

In my my experience this behaviour is caused by either a serialization failure or a message that is to large (64KB is the default max messages size). 以我的经验,此行为是由序列化失败或消息过大(默认的最大消息大小为64KB)引起的。 This causes WCF to crash silently (yes, I don't understand that design choice either), but still remove the message from the queue. 这将导致WCF 静默崩溃(是的,我也不理解该设计选择),但仍从队列中删除该消息。

Just enable Tracing and you'll quickly see the exception in WCF that causes this. 只需启用跟踪,您就会很快在WCF中看到导致这种情况的异常。

Add this to your web.config (I have it just below </system.webServer>) for a crude trace setup. 将此添加到您的web.config(位于</system.webServer>下面)中进行粗略的跟踪设置。 Make sure the AppPool user has write access to the logging folder. 确保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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM