Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating two applications one is console app which will be send messages to the client machines(MSMQ). And another one MSMQ with WCF service which resides in all the client machines and reads all the messages from Private queue. My console application working fine means it is sending messages to client machines. But WCF service does not picking up the messages from queue automatically. Please help me in resolving this issue.

It would be a great help.

I). Following is my Interface:

C#
namespace MessageReceiver
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    [ServiceKnownType(typeof(MessageContainer))]
    public interface IMessageHandlerService
    {
        [OperationContract(IsOneWay = true, Action = "*")]
        void ProcessIncomingMessage(MsmqMessage<MessageContainer> incomingOrderMessage);
    }
}


II). Following is my implementation class

C#
public class MessageHandlerService : IMessageHandlerService
    {
        #region IMessageHandlerService Members

        [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
        public void ProcessIncomingMessage(MsmqMessage<MessageContainer> incomingOrderMessage)
        {
            //processing incoming messages
        }

        #endregion
    }


III). Following is my contracts

C#
namespace MessageReceiver
{
    [DataContract]
    public class MessageContainer
    {
        public MessageContainer()
        {
        }

        [DataMember(IsRequired = true)]
        public string ProcessName { get; set; }

        [DataMember(IsRequired = true)]
        public string RoboName { get; set; }

        public MessageToRobo msg { get; set; }
    }

    public class MessageToRobo
    {
        [DataMember(IsRequired = true)]
        public string Value1 { get; set; }

        [DataMember(IsRequired = true)]
        public string Value2 { get; set; }

        [DataMember(IsRequired = true)]
        public string Value3 { get; set; }
    }
}


IV). Following is my web.config
XML
<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <!--newly added code starts-->
      <endpointBehaviors>
        <behavior name="IncludeExceptionDetails">
          <callbackDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </endpointBehaviors>
      <!--newly added code ends-->      
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--newly added code starts-->
    <services>
      <service name="MessageReceiver.MessageHandlerService">
        <endpoint address="msmq.formatname:DIRECT=OS:MachineName\private$\MessageForRobo" binding="msmqIntegrationBinding" bindingConfiguration="IncomingMessageHandlerBinding" contract="MessageReceiver.IMessageHandlerService">
        </endpoint>
      </service>
    </services>
    <bindings>
      <msmqIntegrationBinding>
        <binding name="IncomingMessageHandlerBinding"
                 closeTimeout="00:30:00"
                 receiveTimeout="01:00:00"
                 retryCycleDelay="00:00:10"
                 receiveRetryCount="0"
                 exactlyOnce="true"
                 maxRetryCycles="3"
                 receiveErrorHandling="Move">
          <security mode="None"/>
        </binding>
      </msmqIntegrationBinding>
    </bindings>
    <!--newly added code ends-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <!--newly added code starts-->
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing, All" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\DNCTrace.svclog"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <!--newly added code ends-->
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>
Posted
Updated 22-Dec-15 2:33am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900