简体   繁体   English

WCF MsmqIntegrationBinding - 不从队列中选择消息

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

I have a legacy client that is writing messages to a queue (MSMQ). 我有一个旧客户端正在将消息写入队列(MSMQ)。 I wanted to use a WCF service to pick the XML messages up off of the queue. 我想使用WCF服务从队列中挑选XML消息。 I followed some of the MSFT docs and poked around at other examples, but i can't seem to get it to work. 我跟着一些MSFT文档并在其他示例中探讨过,但我似乎无法让它工作。 The service host is starting, but it is not firing my process and picking messages off of the queue. 服务主机正在启动,但它不会触发我的进程并从队列中挑选消息。 Most likely user error, just not sure what. 最有可能的用户错误,只是不确定是什么。

I can see messages in the queue? 我可以在队列中看到消息吗?

Code Example: 代码示例:

   [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 Config: 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>

Not sure what I am doing wrong? 不确定我做错了什么?

--S --S

In your config the following element needs to be as shown below: 在您的配置中,以下元素需要如下所示:

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

Your service name above doesnt include a namespace, it should always be a fully qualified name of the service 上面的服务名称不包含命名空间,它应始终是服务的完全限定名称

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

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