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;