Asp. NET upload file through remoting service _ practical skills

Source: Internet
Author: User

Recently, because in the study remoting, pure just understand, discover remoting is really good thing.

We usually have three ways to use remoting, one of which is

First: Publishing a public object
The exposed object is created locally
Second: Remote creation of a public object (SAO)
Object created in client request
Third: Remote creation of a private object (CAO)
object is created on the host, and the client references the object on the server

I don't really understand the essence of these three kinds of differences. These three ways of remoting are not created the same way.

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 (objects) needs to inherit from the MarshalByRefObject class.

How do I transfer files in remoting? The basic idea is to call the host's object after the client opens the client's file and converts it to the byte[] type.
Objects transferred between 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 to Kaction, save it under 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. When you are ready to send to host, you are prompted to "include potentially dangerous types."
[Serializable]
public struct kaction
{
public string filename;
Public byte[] context;
Public Fineinfo fileinfo;//Here

};
Make a note of your own experience. I will tidy up the next time to do a complete point.

Cnzc ' s Blogs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.