Basic Framework solution for Wcf communication (I)-Basic Structure

Source: Internet
Author: User

As we hope to use Wcf as the communication framework within the company, we have made some extensions Based on Wcf for the following purposes:

1) to reduce the complexity of client calls, the call method is simplified to WcfServiceLocator. Create <ITestService> (). Add (1, 2 ). You do not need to consider the following issues: endpoint configuration, channel creation, and channel problems.

2) to reduce the server configuration complexity, there is no configuration file (or the configuration file does not need to be changed), and all metadata related to the service is in the database, so the client is not configured.

3) There is a background for managing all the metadata configurations, and you can notify the relevant clients to re-establish the channel when the configuration changes, and notify the relevant server to restart the service.

4) for simple routing functions, such as prioritizing the IPC/TCP channel rather than the HTTP channel, the clients that reference the service contract of a higher version preferentially access the server of the service contract of the higher version. That is to say, in the production environment, if the contract is not compatible, you can open a group of high-version Server clusters, and the client updates the contract one by one, and introduce the High-version server one by one, after all the updates are completed, remove the server of the old version.

5) I pay great attention to cross-cutting concerns and hope that the entire framework will establish logs in the following dimensions:

A) call information, which is recorded after the client calls the remote method and after the server completes the remote method execution, information such as the method name, service name, time required, version at both ends, and machine name at both ends of the call can be recorded.

B) startup information, which is recorded when the client establishes the channel factory for the first time and when the server starts the service for the first time.

C) message information, messages received and sent by the client, messages received and sent by the server

D) exception information, server exceptions, packaged exceptions received by the client

6) These logging policies are configured in the database, and logs are stored in the storage, using the Nosql Technology of Mongodb.

In a word, service consumers and providers only need to consider how to write services, and other basic tasks such as configuration, deployment, and cross-cutting do not need to be considered. Configuration concentration is good for deployment, various logs with independent switches are good for troubleshooting.

The overall structure is as follows:

1) ConfigCenter is a website with two functions: one is to provide the configuration background, and the other is to implement IWcfConfigService, which is exposed to provide services:

Public interface IWcfConfigService
{
[OperationContract]
WcfService GetWcfService (string serviceType, string serviceContractVersion, string machineName); // server configuration

[OperationContract]
WcfClientEndpoint GetWcfClientEndpoint (string serviceContractType, string serviceContractVersion, string machineName); // client endpoint

[OperationContract]
ClientLogConfig GetClientLogConfig (string serviceContractType); // cross-cutting configuration of the Client

[OperationContract]
ServerLogConfig GetServerLogConfig (string serviceContractType, string machineName); // cross-cutting configuration of the server
}

The configuration information is saved in MSSQL, and configuration is provided in the background. In addition, after the configuration is modified, messages are published to Redis, and all clients and servers subscribe to these messages. Implement publishing and subscription of configuration changes.

2) LogService is also a website that allows you to view various logs and provide the Implementation of IWcfLogService:

Public interface IWcfLogService
{
[OperationContract]
String Health (); // heartbeat, switch to local Log service when unavailable

[OperationContract (Name = "LogList", IsOneWay = true)]
Void Log (List <AbstractLogInfo> logInfo );

[OperationContract (Name = "LogOne", IsOneWay = true)]
Void Log (AbstractLogInfo logInfo );
}

After logs are collected, they are written to Mongodb through a queue and viewed in the background.
3) WcfExtension is the Framework subject, which consists of four parts:

A) The Client is all things related to the Client channel, proxy, and behavior. It can collect the called proxy and logs.

B) Server is everything related to the Server, including service IOC, various log collection, exception handling, and service behavior.

C) Log includes the IWcfLogService service contract and the data contract and data collection module.

D) Config includes the IWcfConfigService service contract and related data contract (including the configuration of the framework itself)

4) Clients. Console is a Console client, and the production environment is probably a website. REFERENCE The WcfExtension framework and business service contract.

5) Hosts. Console is a Console-based server. The production environment may be a website or a Windows service. REFERENCE The WcfExtension framework, business service contract, and implementation.

6) WcfExtension. Services. Interface is a service contract and is referenced by the client and the server.

7) WcfExtension. Services. Implementation is a service Implementation that is only referenced by the server.

This article only introduces the basic architecture, and will introduce some implementations and provide the source code.

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.