2

I have a local private queue. I also have a WCF-service inside an MVC-application that listens to the queue using 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?

4

2 回答 2

1

尝试使用 ServiceKnownType 属性修改您的服务合同:

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

更新

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

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

此处记录了允许值。

于 2012-07-25T09:16:20.370 回答
0

以我的经验,这种行为是由序列化失败或消息太大(64KB 是默认的最大消息大小)引起的。这会导致 WCF静默崩溃(是的,我也不理解该设计选择),但仍会从队列中删除消息。

只需启用跟踪,您将很快在 WCF 中看到导致此问题的异常。

将此添加到您的 web.config(我在 </system.webServer> 下方)以进行粗略的跟踪设置。确保 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>
于 2013-06-24T12:27:05.623 回答