Home > Backend Development > C#.Net Tutorial > Detailed explanation of examples of uploading files through Remoting service in ASP.NET

Detailed explanation of examples of uploading files through Remoting service in ASP.NET

巴扎黑
Release: 2017-05-21 18:34:08
Original
1395 people have browsed it

Recently, I am learning Remoting, just to understand it, and I found that Remoting is indeed a good thing.

We usually have three ways to use remoting, one is

The first one: Publishing a public object
The public object is created locally
The second one: Remote creation of a public object (SAO)
The object is created in the client request
Third type: Remote creation of a private object (CAO)
The object is created on HOST, and the client refers to the object on the server

Contents I don’t have a good understanding of the essential differences between these three types. The remoting creation methods of these three methods are also different.

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");
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 (object) to allow remote call processing, then this object ( object) needs to inherit from the MarshalByRefObject class.

How to transfer files during remoting? The basic idea is to open the client's file in the client, convert the Byte[] type and then call the host object.
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 reads the Kaction, save it to the specified file Clip below
MemoryStream meoeryStream=new MemoryStream(k_Action.context);
FileStream fileStream=new FileStream(@"d:\"+k_Action.filename,FileMode.Create);
meoeryStream.WriteTo(fileStream) ;
             fileStream.Close(); When preparing to send to HOST, it will prompt "contains potentially dangerous types".
[Serializable]
public struct kAction
{
public string filename;
public byte[] context;
public FineInfo fileInfo;//here

};

Record your own thoughts. When I have time, I will sort it out and make a complete article next time.


cnzc's blogs

The above is the detailed content of Detailed explanation of examples of uploading files through Remoting service in ASP.NET. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template