您的位置:首页 > 其它

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

2008-04-09 17:10 579 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: