Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.Net Remoting + Winnows Service Acting as a Server

Status
Not open for further replies.

stardv

Technical User
May 27, 2004
33
US
I am trying to implement .Net Remoting to have Windows Server acting as a server for hosting the object and have some client application to connect to the server when needed to activate and use the object. I am new to both windows services and .Net Remoting so it is a challenge to implement for me. Could you share you expertise with me please. I brushed up a little bit on the Windows Services and .Net Remoting and was able to short test implementation to feel how it works. I was successful at that point. However when I tried to combine Win Service and Remoting I filed to grasp some ideas. Could you help me please.
I want to make Windows Server a server hosting a remote object. This is the code I sued to do that:
TcpChannel tcp = new TcpChannel(8085);
ChannelServices.RegisterChannel(tcp);
RemotingConfiguration.RegisterWellKnownServiceType(
Type.GetType("Object.obj,Object"),"Test",
WellKnownObjectMode.SingleCall);

Do I include this portion of the code in OnStart method? What I tried and win service failed to start indicating that it has no job to do.
Or may be I have to start a separate thread in OnStart method that will include above code.

Any help or suggestions will be appreciated.

Thank you so much


Regards, Dmitry
 
For the client, somewhere so this stuff gets initialized and connected, I just used my constructor, but could go wherever you need it:

HttpChannel chan = new HttpChannel(0); //create a new channel, but use port 0, so we can't listen
ChannelServices.RegisterChannel(chan); //register our channel with channselservices


//MarshalByRefObject obj;
obj = (MarshalByRefObject)RemotingServices.Connect(typeof(Distributed_Calc.ICalc), " //set our remoting services object to the type of our interface, and specify the location of the application


For the server to setup remoting:
We have a server class, and a class which implements an interface (the interface is used to have common methods between the server and the client.)

/// <summary>
/// Server class, implements our server functionality, creates a channel, registers it, and listens for connections
/// </summary>
public class Server
{
/// <summary>
/// Our server bits in here!
/// </summary>
public static void Main()
{
HttpChannel channel = new HttpChannel(4000); //create our new channel to listen on, used HTTP because it's simple, and doesn't
//requre a sustained tcp connection
ChannelServices.RegisterChannel(channel); //register our channel with CLR channel services, (we're listening on that port now)

Type calc = Type.GetType("Distributed_Calc.Calculator"); //Get the type of the object so we can register a service type
//pass in full name of object we want

RemotingConfiguration.RegisterWellKnownServiceType //register our well known object, using our type, the endpoint (entry point of app)
(calc, "EndPoint", WellKnownObjectMode.Singleton); // like a web address, and our object mode is singleton, which means that the
//same object will be used until termination of connection, while SingleCall
//would create a new object upon each method

Console.WriteLine("Press enter to exit.");
Console.ReadLine(); //wait for user input
}
}

The weevil of doooooooooom
-The eagle may soar, but the weasel never gets sucked up by a jet engine (Anonymous)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top