Basic Framework solution for Wcf communication (6) solution description and source code

Source: Internet
Author: User

Source code see http://wcfextension.codeplex.com/

Note:

1) I didn't plan to open source so early. This is just a primitive implementation. Please do not use it directly in a commercial environment.

2) Note the authorization terms of this framework: Apache License 2.0

3) The external assembly or framework on which this framework depends is copyrighted by the original author.

4) Many functions may be added after the Framework. Pay attention to the project homepage even if you obtain the latest information.

Decompress the code to open the sln file and you can see this structure.

1) WcfExtension is the core framework:

The Client folder contains some code used by the Client. The Server is naturally the code used by the Server.

Log is the Log-related code (four types of logs), and Config is the configuration-related code.

Setting is the code set by the framework itself (for example, whether to record logs for configuration)

Other code is stored in the parent folder. Of course, some files are stored here for releasing the nuget package.

As for nuget, I don't want to introduce it much. (The nupkg package will be generated in ReleasePackages after the project is compiled using the release method)

2) WcfExtension. ConfigCenter is the background for configuring services and configurations.

A) redis address and notification channel name

B) SQL server configures the database connection string

C) configure the Service's wcf Server Configuration

Note the following points:

A) if you do not want to save your configuration in SQL server, you can rewrite WcfConfigService. cs.

B) the background is very simple. It is a WFWcfConfig. aspx and can be rewritten completely.

3) WcfExtension. LogCenter is the log service and Log Viewing backend. The configuration is similar to 2), but you must use different ports.

WcfLogService. cs is also a simple implementation for reference only. The implementation process is as follows:

A) Save to memory queue

B) Several threads regularly save data to mongodb in batches

For ConfigCenter and LogCenter, you should also note that in the production environment, for high availability, IIS can be used to carry tcp's wcf Service for load balancing.

To make the test simple, there are two temporary Console applications in the solution to replace ConfigCenter and LogCenter.

4) WcfExtension. Clients. Console is the Console client for testing. It should only rely on the WcfExtension framework and service contract, that is, WcfExtension. Services. Interface.

5) WcfExtension. Hosts. Console is the test Console server. It depends on service interfaces and Service implementations, as well as the WcfExtension framework.

6) WcfExtension. Services. Interface is a service contract and defines some simple testing methods.

7) WcfExtension. Services. Implementation is a service Implementation. The LogService under it is used to test service dependency injection.

8) the Libs directory contains some dependent assemblies, mainly redis clients, mongodb clients, and unity, log4get, and nuget.

This is because you can start the project to test:

Start the configuration service and Log service, then start the server, and then start the client.

Before running, you also need to create a table structure and simulate data (if you are afraid of trouble, you can directly reply to the WcfConfig. bak database file in the package), and run db. SQL in WcfExtension. ConfigCenter to create a data table.

You can directly Open Table configuration data or use the configuration background. First, create a Binding:

Then create a service endpoint ServiceEndpoint, corresponding to the binding:

Then create a Service:

Then create the ServerFarm cluster of the Service:

The client endpoint is ClientEndpoint:

And client access to the cluster ClientAccess:

After four projects are started, you can see:

1) Various logs appear on the log service console.

2) messages sent and received are displayed on both the client and server.

3) If you modify the configuration in the background and click the notification button, the client and server should receive the modification notification, and then delete the corresponding cache or restart the service to make the configuration take effect immediately.

(In fact, it is unlikely to notify the server to restart the service in the production environment)

I have said this several times before, and the code is not complex, so you can understand the 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.