1

I have a WCF Windows Service that retrieve MSMQ messages. The SubmitPurchaseOrderInMessage doesn't seem to get called neither do I see any messages in the queue. Code is shown below.

WCF class:

public class OrderProcessorService : IOrderProcessor
{
    [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
    [ServiceKnownType(typeof(MyOrder))]
    public void SubmitPurchaseOrderInMessage(MsmqMessage<MyOrder> ordermsg)
    {
        MyOrder po = (MyOrder)ordermsg.Body;
        Console.WriteLine("Processing id:{0}, name:{1} ", po.ID, po.Name);
    }

    public static void Main()
    {
        //init queue
        if (!MessageQueue.Exists(Constants.QUEUE_PATH)) MessageQueue.Create(Constants.QUEUE_PATH, true);

        //init wcf host via code
        Uri baseUri = new Uri("http://localhost:7878/msmqsvc");
        using (ServiceHost host = new ServiceHost(typeof(OrderProcessorService),baseUri))
        {
            //add metadata behavior
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior(){ HttpGetEnabled=true};
            host.Description.Behaviors.Add(smb);

            //add service endpoint
            MsmqIntegrationBinding binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.None);
            binding.SerializationFormat = MsmqMessageSerializationFormat.Binary;
            host.AddServiceEndpoint(typeof(ClassLib.IOrderProcessor), binding, "msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);

            host.Open();

            // The service can now be accessed.
            Console.WriteLine("The service is ready.");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.ReadLine();
            host.Close();
        }
    }
}

Interface Contract:

[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
[ServiceKnownType(typeof(MyOrder))]
public interface IOrderProcessor
{
    [OperationContract(IsOneWay = true, Action = "*")]
    void SubmitPurchaseOrderInMessage(MsmqMessage<MyOrder> msg);
}

The array Parameters can be any dynamic serializable type that can be passed by client. I think issue is with this parameter. If I remove this parameter and the serializable attribute and also the binding.SerializationFormat in the client, then eveything works fine.

Serializable class:

[DataContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
[Serializable]
public class MyOrder
{
    [DataMember]
    public string ID;

    [DataMember]
    public string Name;

    [DataMember]
    public object[] Parameters;
}

[Serializable]
public class Transaction
{
    public int Amount { get; set; }
}

Client :

 class Program
 {
    static void Main(string[] args)
    {
        try
        {
            Run();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }

    static void Run()
    {
        MsmqIntegrationBinding binding = new MsmqIntegrationBinding();
        binding.Security.Mode = MsmqIntegrationSecurityMode.None;
        binding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
        binding.Security.Transport.MsmqProtectionLevel = System.Net.Security.ProtectionLevel.None;
        binding.SerializationFormat = MsmqMessageSerializationFormat.Binary;
        EndpointAddress address = new EndpointAddress("msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);

        ChannelFactory<ClassLib.IOrderProcessor> channelFactory = new ChannelFactory<ClassLib.IOrderProcessor>(binding, address);

        try
        {
            ClassLib.IOrderProcessor channel = channelFactory.CreateChannel();

            MyOrder order = new MyOrder();
            order.ID = DateTime.Now.Ticks.ToString();
            order.Name = "Order_" + order.ID;
            order.Parameters = new object[] { new Transaction { Amount = 108 }, new Transaction { Amount = 100 } };
            MsmqMessage<MyOrder> ordermsg = new MsmqMessage<MyOrder>(order);

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                channel.SubmitPurchaseOrderInMessage(ordermsg);
                scope.Complete();
            }

            Console.WriteLine("Order has been submitted:{0}", ordermsg);
        }
        catch(Exception ex)
        {

        }
        finally
        {
            channelFactory.Close();
        }
    }
}
1

1 Answer 1

0

Here are some things to check:

  1. Check no messages in temporary outbound queue client-side. If there are messages in this queue it indicates that message cannot be transmitted across the network. Because your queues are transactional this could mean MSDTC configuration (link supports 2012 also).

  2. Check no messages in transactional dead letter queue on service-side. If there are, this indicates a problem delivering the message to the service queue. Likely permissions issue. Service account requires Receive Message and Peek Message on it's queue, client account requires Send Message, Get Permissions, and Get Properties on destination queue.

  3. Enable msmq logging in windows event log. This logs all MSMQ related activity on the box. Service-side for a successful transmission you should see 2 events in the log: Message came over network, and Message with ID was put into queue .

4
  • The error i got is "Unable to find assembly 'WCFClientApp'" The problem is solved (for time being) by moving the Transaction class to the library where the MyOrder is defined. But this does not solved my problem as the objects in the Parameters (field above) is passed from client ( WCFClientApp assembly).
    – arjun
    Jun 30, 2014 at 8:40
  • Yes. But can you please give some idea on the issue above( about dynamic type)
    – arjun
    Jun 30, 2014 at 15:49
  • Why are you passing an array of untyped objects? This is highly unusual. Jun 30, 2014 at 19:36
  • client want to save to disk any transaction data it fails to save (it will invoke webservice to save). Another application will pick up this failed message, try to save the data again. Now this time the second app will create dynamic proxy and invoke the method through reflection. So the challenge is how to save those parameters (to be sent across), as it can be any object and also how to retrieve those parameters.
    – arjun
    Jul 1, 2014 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.