473,498 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Out-of-process COM object in C#

Hi,

Does anyone have an example of doing this?

Regards
Simon.
Mar 21 '06 #1
2 4727
The only supported way is by deriving your class from ServicedComponent and
registering your .NET 'COM' object as a COM+ server type application.
Search the docs for System.EnterpriseServices it must contain some samples I
guess.

Willy.

"Simon Hart" <srhartone@[no spam]yahoo.com> wrote in message
news:uL**************@TK2MSFTNGP11.phx.gbl...
| Hi,
|
| Does anyone have an example of doing this?
|
| Regards
| Simon.
|
|
Mar 21 '06 #2
An Enterprise Component Server:

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

namespace MSDN_dagene
{

[Description("My component")]
public interface MineMetoder
{
int Kalkuler(int tall);
}

[ObjectPooling(MinPoolSize=3, MaxPoolSize=10, CreationTimeout=20)]
[JustInTimeActivation(true)]
[Transaction(TransactionOption.Required)]
public class MSDN_2006 : System.EnterpriseServices.ServicedComponent,
MineMetoder
{
public MSDN_2006()
{

}

public int Kalkuler(int tall)
{
try
{
// Do transaction work etc...
ContextUtil.MyTransactionVote = TransactionVote.Commit;
}
catch
{
ContextUtil.MyTransactionVote = TransactionVote.Abort;
}
return tall + 10;
}
protected override void Activate()
{
base.Activate();
}

protected override void Deactivate()
{
base.Deactivate();
}

protected override bool CanBePooled()
{
return true;
}

}
}
Make a strong name file. Set the project to be COM visible.

Eg. a AssemblyInfo.cs file:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
[assembly: ApplicationName("MSDN_dagene")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: Description("MSDN dagene 2006")]
[assembly: AssemblyKeyFile(@"C:\Lars-Inge\Microsoft dagene 2006\Enterprise
components\MSDN_dagene\MSDN_dagene\strongName.snk" )]
[assembly: AssemblyTitle("MSDN_dagene")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MSDN_dagene")]
[assembly: AssemblyCopyright("Copyright © 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(true)]
[assembly: Guid("d0ba9290-fb59-4065-886c-5b62f8d80625")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Install the dll with the command line:
c:\> regsvcs theDll.dll

Open the "control panel" + "Administrative tools" + "Component Services"
You should see it under "COM+ Applications".

The Client.

Make a reference to the server dll-file.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace KlientTrheim
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
// Remember to use the interface here, or it will not work....
MSDN_dagene.MineMetoder dag = new MSDN_dagene.MSDN_2006();
this.textBox2.Text = dag.Kalkuler( 23 ).ToString();
}
}
}

A Win XP Pro can do about 10 client connections to its server object. If you
want more connections the server must be installed on a Win2003
(application) Server.
Regards,
Lars-Inge Tønnessen
http://www.larsinge.com
Mar 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8618
by: FilexBB | last post by:
Hi Folks, I have tried to redirect system.out for a while and then set it back, but it can't set it back as following program snapshot ByteArrayOutputStream baos = new ByteArrayOutputStream();...
4
36723
by: Merlin | last post by:
Hi there, I would like to check if a string is a valid zip code via Javascript. Length and existents are already checked. How can I find out if the string contains characters other than...
2
2315
by: Chua Wen Ching | last post by:
Hi there, I am wondering the difference between attribute and out keywords. Are they the same or does it serve any different purposes? I saw the and out usage in this code, and i had idea,...
9
1704
by: Michi Henning | last post by:
Hi, I'm generating both VB and C# code from language-independent interface definitions, which is why I'm raising this issue. (The problem apppears to be somewhat esoteric, but it is real in my...
4
2355
by: Jon | last post by:
Why are out parmeters included in an BeginInvoke? They seem to do nothing? TestProgam: using System; namespace TempConsole { class App { public delegate void MyDelegate( out byte b, out...
4
2179
by: dlgproc | last post by:
I have a managed C++ DLL that contains the following: MyLib.h: // MyLib.h #pragma once using namespace System; using namespace System::Runtime::InteropServices; namespace MyLib { public...
11
3408
by: dahuzizyd | last post by:
Hi all: I think I had a problem with using out parameter , why the instance of 'SubClass' can't convert to 'BaseClass' ? my code is : ---------------------------------------------- using System;...
6
5045
by: nick | last post by:
For example: public static void FillRow(Object obj, out SqlDateTime timeWritten, out SqlChars message, out SqlChars category, out long instanceId)
6
14371
by: carlos123 | last post by:
Ok guys, check this out! Im getting an error "Error: Index: 0, Size: 0" not sure why. try{ // Create file FileWriter fstream = new FileWriter("database.txt"); BufferedWriter...
1
12165
by: ccarter45 | last post by:
What am I missing? import java.util.Scanner; public class MathTutor { public static void main( String args ) { int choice; choice = printMenu();
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.