Wince5.0 mobile platform development notes (sharing data variables between AppDomains)

Source: Internet
Author: User

During the project development process, two clients are deployed on the client due to project requirements.. NET applications need to share a variable, that is,. NET application sets the value of the variable, then in another.. NET application can read the set value. To put it simply, variables need to be shared across different AppDomains.

We know that there are several methods for communication between processes:

1. Serial RS232 communication (custom data format, poor versatility, and challenges in error)

2. socket (custom format, error verification)

3. RPC (Remote Call)

4. DCOM (distributed components)

5. Web Service

6. remoting (Remote Object Model)

7. WCF (new-generation SOA Framework)

8. File Reading, etc. (share lock, conflict, etc)

9. The command line parameters of the program .... (Passed when the program is started)

10. MSMQ...

There are many ways of communication between processes, which determine the method to meet the project's purpose or requirements based on the project's needs and the running environment of the program.

Finally, we decided to adopt remoting in the project for the following reasons:

1. winform Applications Based on. NET 2.0

2. Development efficiency (the socket needs to define its own format)

3. Depend on other resources (such as files) as much as possible)

In addition, the remoting technology itself is one of the better ways to call distributed objects among. net programs. In addition, the development efficiency is high in terms of configuration.

Supplement: remoting Development Process:

1. remoting framework

2. Two meanings of remote objects:

Remote Object operation: the object runs remotely, and the client sends a message to the object named alalbyrefobject.

Transmit remote object: Get the remote object to the local device or send the local object to the remote device. Operate on the replica [serializable] Or iserializable

3. Who will activate the object?

3.1 server activation (wellknown): it is the same for all clients. Regardless of customers

3.1.1 Singleton

3.1.2 singlecall

3.2 client activation: You can save the session status for each client.

4. Channel)

A remote object uses a channel to send and receive messages.

Remoting provides built-in channels: TCP channel and HTTP channel, custom Channel

5. remoting development steps:

5.1 create a remote object (Object-Oriented)

Inherited from system. Fig, for example: public class hellotest: FIG {}

5.2 create a Host Program

5.2.1 registration channel: built-in channel: TCP, HTTP

5.2.2 register the remote object activated by the server (wellknown)

Singleton, singlecall

URL

5.2.3 run the Host Program

5.3 create a client program

5.3.1 registration channel: built-in channel: TCP, HTTP

5.3.2 obtain the object proxy Based on the URL

5.3.3 use a proxy to call a remote object

 

The following describes how to implement variable access across different AppDomains in the project:

1. Remote Object:

Code

Public class extends datalist: extends albyrefobject
{
Public static string synchronized data = string. Empty; // static variables are shared among different. NET applications.
Public writable datalist ()
{
Console. writeline ("receivdatalist activated ");
}
Public void setdata (string data)
{
Required data = data;
}
}

 

2. Server (Host Program)

Code

Public static int main (string [] ARGs)
{
Console. writeline (jsondatalist. jsondata );
Tcpchannel chan1 = new tcpchannel (8085 );
Channelservices. registerchannel (chan1, false );
Remotingconfiguration. registerwellknownservicetype
(
Typeof (sharedatalist ),
"Collect data ",
Wellknownobjectmode. Singleton
);

System. Console. writeline ("Press ENTER key to exit ");
System. Console. Readline ();
Console. writeline (jsondatalist. jsondata );
System. Console. Readline ();
Return 0;
}

 

3. Client

Code

Public static void main (string [] ARGs)
{
// Obtain the remote object through the TCP Channel
Tcpchannel chan1 = new tcpchannel ();
Channelservices. registerchannel (chan1, false );
Sharedatalist obj1 = (sharedatalist) activator. GetObject (
Typeof (remotingsamples. includatalist ),
"TCP: // localhost: 8085/Dynamic Data ");
If (obj1 = NULL)
{
System. Console. writeline (
"Cocould not locate TCP server ");
}
Obj1.setdata ("one value passed to another. NET application"); // call a remote object to set the value of the shared variable
Console. Readline ();
}

 

Through the above Code, the client calls the setdata () method to set the value of the shared variable sharedata, so that the server can directly obtain the value of the configured Slave Data. This is achieved technically, and of course it meets the requirements of the project.

Best regards,

Charles Chen

Http://charles2008.cnblogs.com/

 

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.