One step by step by step, one: from simple start

xiaoxiao2021-03-13  192

First, Remoting's advantages and disadvantages?

Advantages: 1, let us distribute development 2, the Remoting speed of the TCP channel is very fast 3, although it is remote, but very close to the local call object 4, you can maintain the status of the object 5, no application restrictions, It can be a console, WinForm, IIS, Windows service bearer remote object disadvantages: 1. Non-standard applications therefore there is platform limit 2, if you are separating IIS, you need your own security mechanism.

Second, the difference between Remoting and Web services? The ASP.NET Web Services The infrastructure provides a simple API for web services by mapping the SOAP message to method calls. This mechanism is implemented by providing a very simple programming model (based on the SOAP message exchange mapping to method call). The client of the ASP.NET Web service does not need to understand the platform, object model, or programming language for creating them. The service does not need to understand the client to send a message. The only requirement is that both parties must recognize the format of the SOAP message being created and used, which is defined by the Web service contract definition represented using the WSDL and XML architecture (XSD). Net remoting provides an infrastructure for distributed objects. It uses both flexible and scalable pipelines to provide .NET full object semantics. ASP.NET Web Services provides a very simple programming model based on messaging, while .NET Remoting provides more complex features, including supporting values ​​or reference delivery objects, callbacks, and multi-object activation and lifecycle management strategies. To use .NET Remoting, the client needs to know all of these details, in short, you need to use the .NET to establish the client. The .NET Remoting line also supports SOAP messages, but must pay attention to this does not change its requirements for the client. If the Remoting endpoint provides .NET dedicated object semantics, whether or not through SOAP, the client must understand them.

Third, the simplest remoting example 1. Remote object: Create a library project: RemoteObject

Using

System;

Namespace

RemoteObject {

public

Class

MyObject: MarshalByrefObject {

public

int

Add (

int

a,

int

b) {

Return

a

b;}}}

2, the server builds a console project: RemoteServer

Using

System;

Using

System.Runtime.Remoting;

Namespace

RemoteServer {

Class

Myserver {[stathread]

Static

Void

Main

String

[] Args) {remoteConfiguration.configure (

"

RemoteServer.exe.config

"

Console.readline ();}}}

Establish a configuration file: app.config

<

CONFIGURATION

>

<

SYSTEM

.Runtime.remoting

>

<

Application

Name

= "RemoteServer"

>

<

Service

>

<

Wellknown

Type

= "RemoteObject.myObject, RemoteObject" Objecturi

= "RemoteObject.myObject"

Mode

= "Singleton"

/>

Service

>

<

Channels

>

<

Channel

Ref

= "TCP"

port

= "9999"

/>

Channels

>

Application

>

System.Runtime.Remoting

>

CONFIGURATION

>

3, the client:

Establish console project: RemoteClient

Using

System;

Namespace

RemoteClient {

Class

MyClient {[stathread]

Static

Void

Main

String

[] Args) {remoteObject.myObject App

=

(RemoteObject.myObject) activator.getObject (

Typeof

(RemoteObject.myObject), System.configuration.configurationSettings.AppSettings [

"

ServiceURL

"

]); Console.writeline (app.add

1

,

2

)); Console.readline ();}}}

Establish a configuration file: app.config

<

CONFIGURATION

>

<

Appsettings

>

<

Add

Key

= "ServiceURL"

Value

= "TCP: // localhost: 9999 / remoteObject.myObject"

/>

Appsettings

>

CONFIGURATION

>

4, testing when compiling: 1, find app.add () 2, can't find RemoteObject This is because client RemoteClient does not add RemoteObject's reference, the compiler does not know which remote objects exists. Members so error, after adding references, vs.net will save a DLL on the client, maybe everyone will ask if it is very troublesome if the modification of the remote object is? In fact, it is not trouble, and the project is compiled once vs.net will replicate the DLL. Then directly run an exception of the "Target Host Reject", and also shows that the channel does not open the running server and then run "Find the assembly RemoteObject"! Looking back Thinking we can find us and add a reference to RemoteObject on the server, because it is because it doesn't use a remote object at this time, everyone may not understand when running the server? This is because there is no activation of the remote object at this time. For example, the service end should add a reference remote object, after all, our object is to rely on remote bearer. Now run the server program and client program, the client program is displayed 3, and the test is successful. IV. Conclusion We have implemented the simplest remoting through a simple example. I don't have any introduction to the essence. I want to introduce an example to be the easiest.

转载请注明原文地址:https://www.9cbs.com/read-129176.html

New Post(0)