2012-07-25 70 views
2

我有一個本地專用隊列。我還有一個MVC應用程序內的WCF服務,該應用程序使用msmqIntegrationBinding監聽隊列。問題在於,當消息排隊時服務契約永遠不會被調用,但消息在此後消失。該消息不在毒物隊列中。這裏就是我宣佈綁定到隊列的配置部分:MSMQ,消息放入隊列並消失,但從未被服務合同拾起

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

這裏是在服務的方法:

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

爲什麼消息消失但不調用服務的任何建議?

+0

作爲一個感興趣的問題,爲什麼使用MsmqIntegrationBinding?您的隊列客戶端是否在傳統平臺上? – 2012-07-25 09:19:17

回答

1

嘗試用ServiceKnownType屬性修改服務合同:

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

UPDATE

如果您正在使用MsmqIntegrationBinding我假設您的隊列客戶端像VB6客戶端遺留應用程序?如果是這樣,您將需要在服務綁定配置中指定序列化格式。例如:

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

允許值記錄在here

+0

我試着做了兩件你建議的事情,它不起作用。 – Spetastium 2012-07-25 14:02:03

+0

您是否使用集成綁定是有原因的? – 2012-07-25 14:04:36

+0

是的,所以當服務在後臺到達隊列時,服務會自動收到消息。這不正確嗎? – Spetastium 2012-07-25 14:41:37

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>