Using WCF to realize remote monitoring of unmanned terminals

Source: Internet
Author: User
Tags foreach static class

Recently, in your project, you have encountered an example of a real-time situation where you need to remotely monitor the software running automatically. Because MS has WCF for service-oriented aspects, and read some information, WCF is more suitable for this application. Therefore, we decided to use WCF to implement this function.

First of all, the specific application, monitoring, as the name suggests, there are two aspects of the meaning, on the one hand is "supervision", that is, remote to be able to real-time view of the terminal situation. Here actually refers to be monitored to be able to active, real-time to the remote control to send their own situation. The other is control, that is, the remote side can release command control terminal to execute. And a certain execution information is returned by the terminal.

And here is a one-to-one relationship, where a terminal can be monitored by multiple management terminals. In fact, a management end can also monitor multiple terminals, in this analysis, we can understand that the real operation of the service is the terminal, rather than the management side.

For simplicity, assume that the operation of the remote Send command is void Operation (), and that the terminal update is UpdateStatus ();

This idea, from design to implementation, undergoes the following three stages of deformation.

The original idea was to be a service class. An interface. That

That is, the control-side calls the operation to send the command, the terminal calls the UpdateStatus update state.

Corresponding, must have a certain callback, namely the control end sends the operation, the terminal must have a callback to receive, corresponding, when the terminal uses UpdateStatus, the control end also must have a callback to receive.

When both of these operations are integrated into a service, our WCF interface becomes the following structure.

namespace GEYUNFEI.WCF


{


[ServiceContract (





SessionMode = sessionmode.required


   ,


callbackcontract = typeof (Isevicecallback)


         )]


public Interface IService


    {


[OperationContract]


///<summary>


///Remote Send control command


///</summary>


        ///


void Operation ();





[OperationContract]


///<summary>


///Update Status


///</summary>


void UpdateStatus ();


    }


   


public Interface Isevicecallback


    {





     


void Receivestatus ();


       


void Receivecommand ();


    }


public static class Global


    {


public static list<isevicecallback> callbacks = new list<isevicecallback> ();


    }


[ServiceBehavior]


public class Service:iservice,idisposable


    {


Isevicecallback CallBack;


#region IService Members


public Service ()


        {


callBack = system.servicemodel.operationcontext.current.getcallbackchannel<isevicecallback> ();





Global.callBacks.Add (CallBack);


          


        }





///<summary>


///When the server calls this, send a command to the terminal


///</summary>


public void Operation ()


        {





foreach (Var r in Global.callbacks)


            {


R.receivecommand ();


            }


        }


<summary>


///when the terminal calls, send a command to the server


///</summary>


public void UpdateStatus ()


        {


foreach (Var r in Global.callbacks)


            {


R.receivestatus ();


            }


        }





#endregion





#region IDisposable Members





public void Dispose ()


        {


Global.callBacks.Remove (This.callback);


        }





#endregion


    }


}

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.