Recently in because of learning remoting, purely just to understand, found that remoting is really good things.
We usually have three ways to use remoting, one is
First type: Publishing a public object
Exposed objects are created on-premises
Second type: Remote creation of a public object (SAO)
Object creation in the client request
Third type: Remote creation of a private object (CAO)
object is created on the host, the client references the object on the server
I do not have a good understanding of the three kinds of essential differences in the contents. And these three ways of remoting are created in different ways.
The first way
Host:
ChannelServices.RegisterChannel (New TcpChannel (1500));
Ctransfer Trans = new Ctransfer ();
Remotingservices.marshal (Trans, "Testservice"); Client:
Ctransfer T = (ctransfer) Activator.GetObject (typeof (Ctransfer),
"Tcp://host:1500/testservice");
The second way
Host:
ChannelServices.RegisterChannel (New TcpChannel (1500));
RemotingConfiguration.RegisterWellKnownServiceType (typeof (Ctransfer),
"Testservice", Wellknownobjectmode.singleton); Client:
Ctransfer T = (ctransfer) Activator.GetObject (typeof (Ctransfer),
"Tcp://host:1500/testservice");
The Third Way
Host:
ChannelServices.RegisterChannel (New TcpChannel (1500));
Remotingconfiguration.registeractivatedservicetype (typeof (Ctransfer)); Client:
Object[] attr = {new Urlattribute ("tcp://host:1500")};
object[] args = {"Sample constructor argument"};
Ctransfer T = (ctransfer) activator.createinstance (typeof (Ctransfer), args, attr);
If we need an object to allow remote invocation processing, then this object needs to inherit from the MarshalByRefObject class.
How do I transfer files in remoting? The basic idea is to call the host object after the client opens the client's file and converts it to the byte[] type.
Objects that are transferred between the client and host
[Serializable]
public struct kaction
{
public string filename;
Public byte[] context;
Open the file and save the stream bytes to the context.
Stream Filestream=file.open (This.transfilename.text,filemode.open);
filestream.position=0;
byte[] Content = new byte[((int) filestream.length) + 1];
FileStream.Read (content,0,content.length);
After the host has read the kaction, save it to the specified folder
MemoryStream meoerystream=new MemoryStream (k_action.context);
FileStream filestream=new FileStream (@ "d:\" +k_action.filename,filemode.create);
Meoerystream.writeto (FileStream);
Filestream.close ();
Meoerystream.close ();
Discovery cannot define a new object in the object. You will be prompted to "include potentially dangerous types" on the ready to send to host.
[Serializable]
public struct kaction
{
public string filename;
Public byte[] context;
Public Fineinfo fileinfo;//Here
};
Keep a record of your experiences. I will tidy up next time to do a full point.
Cnzc ' s Blogs