簡體   English   中英

WCF MsmqIntegrationBinding - 不從隊列中選擇消息

[英]WCF MsmqIntegrationBinding - Not picking Messages off of the queue

我有一個舊客戶端正在將消息寫入隊列(MSMQ)。 我想使用WCF服務從隊列中挑選XML消息。 我跟着一些MSFT文檔並在其他示例中探討過,但我似乎無法讓它工作。 服務主機正在啟動,但它不會觸發我的進程並從隊列中挑選消息。 最有可能的用戶錯誤,只是不確定是什么。

我可以在隊列中看到消息嗎?

代碼示例:

   [ServiceContract]
    [ServiceKnownType(typeof(XElement))]
    public interface IMessageProcessor
    {
        [OperationContract(IsOneWay = true, Action = "*")]
        void ProcessMessage(MsmqMessage<XElement> msg);
    }
    class MessageServiceClient : IMessageProcessor
    {
        [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
        public void ProcessMessage(MsmqMessage<XElement> msg)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                Console.WriteLine("Processing {0} ", msg.ToString());
                scope.Complete();
            }

        }

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);
            // Create a ServiceHost for the CalculatorService type and provide the base address.
            using (ServiceHost serviceHost = new ServiceHost(typeof(MessageServiceClient), baseAddress))
            {
                // Open the ServiceHostBase to create listeners and start listening for messages.
                serviceHost.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("The service is running in the following account: {0}");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                serviceHost.Close();
            }
        }
    }

App配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <!-- use appSetting to configure MSMQ queue name -->
    <add key="QueueName" value=".\private$\MyMessageQueue" />
    <add key="baseAddress" value="http://localhost:8000/test/message" />
  </appSettings>
  <system.serviceModel>
    <services>
      <service name="MessageServiceClient">
        <!-- .Net endpoint-->
        <endpoint address="msmq.formatname:DIRECT=OS:.\private$\MyMessageQueue"
                  binding="msmqIntegrationBinding"
                  bindingConfiguration="DotNetBinding"
                  contract="WcfServiceClient.IMessageProcessor" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MessageServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata />
          <!--<serviceThrottling maxConcurrentCalls="20" maxConcurrentSessions="20" />-->
          <serviceTimeouts />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <msmqIntegrationBinding>
        <binding serializationFormat="ActiveX" name="ActiveXBinding" durable="false" exactlyOnce="false">
          <security mode="None" />
        </binding>
        <binding serializationFormat="Xml" name="DotNetBinding" durable="false" exactlyOnce="false">
          <security mode="None" />
        </binding>
      </msmqIntegrationBinding>
    </bindings>
  </system.serviceModel>
</configuration>

不確定我做錯了什么?

--S

在您的配置中,以下元素需要如下所示:

<services>
      <service name="WcfServiceClient.MessageServiceClient">
        <!-- .Net endpoint-->
        <endpoint address="msmq.formatname:DIRECT=OS:.\private$\MyMessageQueue"  
                  binding="msmqIntegrationBinding"
                  bindingConfiguration="DotNetBinding"
                  contract="WcfServiceClient.IMessageProcessor" />
      </service>
    </services>

上面的服務名稱不包含命名空間,它應始終是服務的完全限定名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM