top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can we do transactions using MSMQ?

+2 votes
364 views

If yes, How?

posted Feb 25, 2014 by Muskan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

While doing MSMQ there can be scenarios in the project, where we would like all the messages are uploaded to either MSMQ or all messages read from MSMQ. After any message is read from MSMQ, it is deleted from the queue. Therefore, some times this can be critical if there are exceptions in reading or uploading messages. As said before WCF transaction can be applied to database as well as other operations like MSMQ. So let us try to understand the same by doing a small sample.
Below is a numbered code snippet of MSMQ transactions.

1 - Send message is the exposed method in the service. We have marked this method as TransactionScopeRequired=true

2 - On the client side we have use the transaction scope to say that we are starting a transaction to MSMQ server. You can see we have used the send Message to send the messages to MSMQ.

3- We can then use Complete or Dispose method to complete or rollback the transactions.
The below MSMQ transaction code ensures that either all messages are send to the server or none are sent. Thus satisfying consistency property of transactions.

answer Feb 25, 2014 by Atul Mishra
Similar Questions
+4 votes

Why returning dataset or data table from WCF service is not a good practice?
What are the alternatives ?

...