MSMQ&Com+ Service: How to create an Com+ Service in .NetFramework

1.create an library project named ComPlusService, and add references to System.EnterprisesServices & System.Messaging;
2.sample codes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
using System.EnterpriseServices;

namespace ComPlusService
{
    [System.EnterpriseServices.TransactionAttribute(
  System.EnterpriseServices.TransactionOption.Required)]
    public class MessageMover : System.EnterpriseServices.ServicedComponent
    {
        private System.Messaging.MessageQueue sourceQueue;
        private System.Messaging.MessageQueue destinationQueue;
        public MessageMover()
        {
        }

        public System.Messaging.MessageQueue Source
        {
            get
            {
                return sourceQueue;
            }
            set
            {
                sourceQueue = value;
            }
        }
        public System.Messaging.MessageQueue Destination
        {
            get
            {
                return destinationQueue;
            }
            set
            {
                destinationQueue = value;
            }
        }
        [System.EnterpriseServices.AutoComplete()]
        public void Move()
        {
            System.Messaging.Message sourceMessage;
            sourceMessage = sourceQueue.Receive(
               System.Messaging.MessageQueueTransactionType.Automatic);
            destinationQueue.Send(sourceMessage,
               System.Messaging.MessageQueueTransactionType.Automatic);
        }
    }
}

set the assemly strong name;
    i) create key pair;
        prompt command: sn -k key.snk;
   and then key.snk will be generated
    set assemlyInfo.cs as following:
        [assembly:AssemblyDelaySign(false)]
        [assembly:AssemblyKeyFile("key.snk")]
        [assembly:AssemblyKeyName("")]

build the project and generate complusservice.dll;

3. register the com+ Services;
prompt command: regsvcs complusservice.dll
//Exception occurs: the transaction manager is not avalible
//solution: prompt command: msdtc -install

4.create a client application to consume the com+ service;


 

你可能感兴趣的:(framework)