30, "C #. NET Development framework "Wcfhosting Service host using WCF service communication and implementation ideas

Source: Internet
Author: User

back to the "open source" EFW Framework Series article index

EFW Framework Source code download V1.3:http://pan.baidu.com/s/1c0dado0

EFW Framework Instance source code download: Http://pan.baidu.com/s/1eQCc69G

Preamble : The previous systems are direct client directly connected to the database server, and then take into account the security of the server, the number of database connections, poor distribution capacity, especially in those years, middleware, SOA, ESB and other fire, in order to keep up with the Times script need to develop a middleware, Run the backend logic business in the middleware. Just started to think about webservices, but need to deploy in IIS, but also the performance problems are more serious, try the effect is not very good, and later think WCF good, but has not found a good way to combine with the existing architecture, If the business code is completely rewritten into a WCF service to the client invocation, it feels a lot of work, the light looks at WCF those configuration file is big, especially destroys the existing program schema, so using WCF is meaningless to the existing framework. Later, in the perfect web version of the framework from the httphandlers, found that there is no need to make the business functions of the WCF services, and WCF service is only used to implement the client and the background business communication, so the middleware only need a WCF service to connect the client controller and the server-side controller, The WinForm version of the controller layer is also split into Wcfclientcontroller and Wcfcontroller. So the original program structure has not changed, to ensure that the Web version, WinForm version, the WCF version of the three types of System program architecture, coding style, etc. are consistent, so that the EFW framework to support a variety of system development;

This article highlights:

1.WCFHosting Service Host Introduction

2.WCFHosting Service Host Implementation

Two issues that 3.WCFHosting service host must address

4. Summary

1.WCFHosting Service Host Introduction

The wcfhosting program is just a WCF self-hosted host, and of course you can modify this program so that WCF services are hosted in IIS or Windows services, The wcfhosting program has only three core functions: the Wcfhandlerservice service is used to realize the client-server communication, RemoteLoader is used to implement the corresponding service-side controller program, and the router service is used to realize the connection routing and load balancing of the middleware.

Source code Project Solution directory:

Wcfhosting Program Interface

Configuration file description, including Client app. Config and Server app. Config two configuration files

1) client's app. Config

Mainly the ClientType parameter and the Wcf_endpoint parameter setting, ClientType must be set to the Wcfclient,wcf_endpoint set to the WCF address;

2) App. Config on the service side

2.WCFHosting Service Host Implementation

1) FrmHosting.cs interface, start and stop WCF service

When you start, you can turn on the function according to the configuration in the settings, such as:

Display debugging information , each client interacts with the server each time the content will be displayed in the log interface

turn on the WCF service , if this host is the middleware of the system then you must tick here

turn on the routing service , if this host is set as a router then you must tick here

Open Heartbeat detection , the formal use of the system must check the last place, if it is the development phase can not tick, easy to debug the program

2) Wcfhandlerservice service, the client connects, executes, disconnects and communicates with the middleware by calling this WCF service

The Iapiwcfhandlerservice contract of the Wcfhandlerservice service uses the CallbackContract callback operation, which realizes two-way communication between the client and the server, and the server can actively send the data to the client. This is a feature that the Web program does not have, and the Web program can only implement this function through timed access.

The Wcfhandlerservice service object has 5 core methods,

CreateDomain: Opening the client (EFWWin.exe program) calls this method to create an online user on the server

ProcessRequest: The client calls this method to access the server-side controller code

Undomain: Client (EFWWin.exe program) Call this method before exiting to clear the server-side online user

Heartbeat: The client, like a heartbeat, calls this method to periodically send an online status to the server

Sendbroadcast: server sends messages to clients

3) Loader objects, managing each connected client, and invoking the WCF controller through reflection

4) Basewcfclientcontroller Client controller base class

5) Basewcfcontroller Service-side controller base class

6) Jsonwcfcontroller client-to-server data exchange based on JSON string format

7) Router service, middleware routing function and load balancing implementation

two issues that 3.WCFHosting service host must address

Problem one: Due to network interruption problems and other problems caused by communication errors, after recovery must be able to continue to use, do not need to shut down the system re-login system, and then the WCF server host must feedback that this client is disconnected state;

Problem two: Due to the WCF host exception to crash, and then reboot to take over all the client connections previously connected to this host, do not require the client to quit the system restart;

Solution to the problem:

Problem one, increase the heartbeat mechanism, let the client periodically send a message to the WCF host, if the timeout is not received to prove that the client disconnects, the network interrupt client automatically reconnect the server, you can set the client to cancel the credentials authentication;

In issue two, the middleware can persist the cached client information, restart the middleware and load the client information of the abnormal exit.

4. Summary

The basic functions of WCF middleware have been realized, which realizes the communication between client and server, and realizes distributed deployment and load balancing of server. However, the middleware is still very simple, such as persistent client connection data, more flexible load balancing algorithm, and many other functions need to be perfected. The implementation of middleware routing and load balancing is explained in detail in the next chapter.

30, "C #. NET Development framework "Wcfhosting Service host using WCF service communication and implementation ideas

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.