Question

I have a legacy client that is writing messages to a queue (MSMQ). I wanted to use a WCF service to pick the XML messages up off of the queue. I followed some of the MSFT docs and poked around at other examples, but i can't seem to get it to work. 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:

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top