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;
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;
相关文章推荐
- All-In-One Code Framework(AIO): 如何使用C#编写进程外的COM组件 (How to write an out-of-proc COM server in C#)
- How to create a zip file in NetSuite SuiteScript 2.0 如何在现有SuiteScript中创建和下载ZIP压缩文档
- How to Pop Open an image window that resizes to fit the image in ASP.net 1.x and 2.0 Beta 1
- How to Confirm a Delete in an ASP.NET Datagrid...
- How to create simple web service in VS2010, NOT WCF service
- How to Create an Video Player in jQuery, HTML5 & CSS3
- How to hide the OK button in the dialog in .Net Compact Framework application?
- How to create simple and advanced pivot tables in C# and ASP.NET
- How to use an ASP.NET application to query an Indexing Service catalog by using Visual Basic .NET
- How to Create a Microsoft .NET Compact Framework-based Image Button
- [Windows Azure] How to use the Windows Azure Blob Storage Service in .NET
- "HOW TO: Create a Smooth Progress Bar in Visual C# .NET"的学习笔记
- [转载]How to hide the OK button in the dialog in .Net Compact Framework application?
- How to use Oracle 11g ODP.NET UDT in an Oracle Stored Procedure's Where clause
- How to create an Excel sheet or chart in VC?
- How to invoke Java web service in ASP.net using C#
- How to create own operator with python in mxnet?
- How to Create an R Package in Windows
- How to use an ActiveX script task to create a loop in DTS
- How to use Oracle 11g ODP.NET UDT in an Oracle Stored Procedure's Where clause