Hello..
I am trying to solve a problem, but I'm not really sure what to call what I am want do as I am fairly new to C# .net.
I
have a Windows Service which basically controls threading and nothing
else. This service calls another .dll (Base Class) which I have added
as a reference to the Windows Service. Now, this Base Class will call
other .dlls or assemblies on the fly (for example I am pulling the name
of the .dll out of a table in the database). I want to be able to
carry all the properties and values from the Base Class to the new .dll
called. I believe serialization is what I am looking for, but every
example I've found works just with one solution with mulitple classes,
not multiple solutions (.dll's).
Make sense?
thanks for your help.
Loading
Bechir BejaouiPosted Aug 13, 2008, 6:10 PM
suppose that you have application client that consumes an object myclass located in other application
first make use of the System.Net; and System.Remoting name spaces
then
derive your object from MarshalByRefObject
like this
// This is a type that will be
// marshaled by reference (MBR) if accessed remotely.
public class myclass: MarshalByRefObject
{
public myclass()
{ }
// This method takes an input string from the caller.
public void DisplayMessage(string message)
{ Console.WriteLine("Message is: {0}", message);}
// This method returns a value to the caller.
public string ReturnMessage()
{ return "Hello from the server!"; }
}
}
inorder to transfert this object you have to build a third parti witch is in fact the server that communicates the object to the client
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
but don't forget to make of the assembly that holds my class in the server one, I mean in addition to those above namesapce you have to in clude
using namespace that contains of myclass
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using ........; /*Assembly of my class*/ ;
add this code to the server main method
// Register a new HttpChannel
HttpChannel c = new HttpChannel(14000);// you can use ports of your choice but they must not be used by other programs like 80 for http or 25 smtp
ChannelServices.RegisterChannel(c);
// Here singleton activation is used.
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(SimpleRemotingAsm.RemoteMessageObject),
"RemoteMsgObj.soap",
WellKnownObjectMode.Singleton);
Console.ReadLine();
in your application that consumes that data use this code to consume myclass object data
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using ........; /*Assembly of my class*/
Console.WriteLine("***** SimpleRemoteObjectClient started! *****");
Console.WriteLine("Hit enter to end.");
// Create a new HttpChannel.
HttpChannel c = new HttpChannel();
ChannelServices.RegisterChannel(c);
// Get a proxy to remote WKO type.
object rmtObj = Activator.GetObject(
typeof(SimpleRemotingAsm.myclass),
"http://localhost:14000/myclass.soap");
// Now use the remote object.
myclass data = (myclass)rmtObj;
simple.DisplayMessage("Hello from the client!");
Console.WriteLine("Server says: {0}", data.ReturnMessage());
Console.ReadLine();