How can 2 .NET EXEs talk to each other?

D

Dave

This may be a simple question, but I'm new to .NET and not having much luck
finding out the answer.

I'm writing a Windows Service and want to develop a separate program that
provides a user interface so the user can control the service. They are both
being developed in Visual C# .NET. What is the best way to get them to talk
to each other?

I've heard of remoting, but not sure that is what I need, it seems kind of
overcomplicated and I'm not all that keen on opening TCP/IP ports. But I'll
read into it further if someone replies and tells me that would do what I'm
trying to achieve. What would be great is if there is a way for the UI
program to call methods in the service like what was possible with ActiveX
EXEs.

I also thought of having the bulk of the service code in a class library,
which both programs could connect to and share data that way. However, both
programs seem to get an entirely different instance of the DLL (I did a test
with static variables) and I can't find a way to make a variable shared
between all programs using the DLL.
 
S

Scott M.

The service code has classes defined in it, yes? If so, just make a
reference to the .exe service and then you can make instances of the classes
in that assembly and call whatever methods you like.
 
D

Dave

When I tried doing this I got the following error....
"A reference to <long filename> could not be added. This is not a valid
assembly or COM component. Only assemblies with extension 'dll' and COM
components can be referenced."

The executable I'm trying to reference is a normal Windows .NET executable
and not the service (I'm trying to get it working with normal apps first
since they're easier to debug) but the impression I get from the error
message is you can't reference any .NET executable.

This is what I tried doing....
Project/Add Reference
Browse (on the .NET tab)
Selected the other compiled exe (debug build) and clicked OK.
 
S

Scott M.

What you've done is correct, but .NET wants to only reference .dll
assemblies, not .exe assemblies. You could just change the file extension
and then it will work (I know that sounds like a hack, but only the ability
to run the .exe directly will be compromised). In .NET, the only difference
between .exe and .dll is the ability to run the assembly directly.
 
D

Dave

If I rename the extension to .DLL will the .DLL still be able to launch as a
service though? Or should I make a separate EXE service that uses the DLL?
 
D

Dave

Thanks, I had looked at some remoting stuff but it just looked a bit
complicated and seemed more concerned with using objects on other PCs over a
network than interprocess communication on the same PC.

Anyway, I had a play around with it today and from what I've seen so far, I
think I can use this to do what I want. Thanks!
 
S

Spare Change

You might want to investigate WSE 2.0

It's a way of doing remoting simply between applications -- not just using
http.

It's the bedrock of MS SOA ( Service Oriented Architecture ) which is all
about inter-app communication.
 
S

Scott M.

You would then make an .exe that calls the .dll. Just using the exe as a
"launch pad" if you will.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top