Winform Enterprise Application Framework Design [2] internal conventions and clients of the team should identify the WCF Service according to the Conventions

Source: Internet
Author: User
Tags what interface

After the first article in this series was published, I discussed some issues with Jun zihaoyu.

(I am an entry-level instructor ~ Awesome Technical Talents ~ Now we are getting involved in the western musical instrument field ~ I hope he can surpass Beethoven as soon as possible ~ Bid for all colleagues in the shanzhai party ~)

I. Responsibilities

The main responsibilities of the client are presented, so there should be no excessive business logic.

Business-relatedCodePut the database-related code on the server.

Put the rendering-related code on the client

As for which code is business-related and which code is rendering-related

Does the rendered Code contain the business, and does the Business Code involve the presentation?

This is a matter of boundary division ~ The wise sees wisdom ~ It also needs to be analyzed based on specific project issues

 

Ii. Fault Tolerance

Both the error tolerant code server and the client have

The service fault tolerance is placed on the server, and the interaction fault tolerance is placed on the client.

(If the client does not do it by yourself, the fault tolerance of the server must be fully covered. This is not the scope of our discussion)

The Fault Tolerance in interaction is different from that in business.

The server determines that the received data is in the correct format, but not necessarily in the business.

 

Iii. Security Issues

For fields with relatively high security requirements, such as Finance

It is necessary to carefully consider the client verification issues,

1. Use a digital certificate

2. Add a string of des ciphertext to the soap message header.

3. Start the client with a dongle

4. Identify the client using the hardware serial number

Advantages and disadvantages ~ Weigh yourself ~ Not discussed in depth

 

Iv. Frame Reuse

A framework on my feet is not used for hundreds of projects,

In many cases, only one or two or three projects are used.

Therefore, do not spend too much effort on compatibility with different business issues.

Some people may say that this is done to maximize the reuse of this framework,

This also depends on the degree of confidence ~ Benevolent sees benevolence ~ The wise sees wisdom ~

Only framework for one project ~ Pretty good ~

We can abstract a lot of business things into the framework to reduce the workload of coding staff, and the framework is not complex and difficult to use!

----------------

V. ORM

Orm is not used in this series ~ Will be used in the next series ~ This is not a commitment

Okay ~ Back to business

I. Internal team agreements

Based on the main menu, we divide the system's business into 12

(Of course, new modules will be added Based on the increase of business, without affecting the existing framework)

Next let's take a look.ProgramSet directory structure

After our framework design is complete

Requires the coding personnel to complete the corresponding business code according to the agreed directory structure

Coding staff hardly need to care about anything unrelated to their own business.

Convention 1:

Code of each module is stored in the corresponding folder.

Convention 2:

The WCF Service Interface Class Name must start with I;

The name of the WCF Service class must end with a service;

Interface Class Name remove I letter = service class name remove service end

Kiss ~ Otherwise, the client cannot find the service.

Convention 3:

Object Class Name must end with Model

The Form class name must end with Form

The database category name must end with da

----

If you think these conventions are too cumbersome ~

Okay ~ Whatever you want ~

Ii. dynamically discover the WCF Service as agreed

With the above conventions, it is easy to dynamically discover the WCF Service.

View code

Public class clientfactory <tclient>: idisposable {static endpointaddress serviceaddress; static basichttpbinding binding; channelfactory <tclient> factory; Public tclient createclient () {factory = new channelfactory <tclient> (binding, serviceaddress); tclient result = factory. createchannel (); return result;} static clientfactory () {var Surl = configurationmanager. appsettings ["serviceurl"]; var INAME = typeof (tclient ). fullname. substring ("XL. serviceapi. ". length); INAME = INAME. replace (". I ","-"); var sname = string. format ("{0} service", INAME); var url = path. combine (Surl, sname); serviceaddress = new endpointaddress (URL); binding = new basichttpbinding (); binding. closetimeout = new timespan (10, 10, 10); binding. opentimeout = new timespan (10, 10, 10); binding. sendtimeout = new timespan (10, 10, 10); binding. receivetimeout = new timespan (10, 10, 10);} public void dispose () {factory. close ();}}

This class requires a "type parameter", which is our service interface type

The static constructor is executed only once.

The basic address of the WCF Service is stored in the appconfig file.

 
<Configuration> <appsettings> <add key = "serviceurl" value = "http: // localhost/XL. Service"/> </appsettings> </configuration>

The next step is to construct a WCF Service address according to the game rules.

For example, http: // localhost/XL. Service/sys-menuservice

(KISS ~ I modified the content of the Service created in the previous article ~)

Static constructor is mainly used for preparation. The createclient method is used to create a service channel.

It provides a tclient instance.

This is an instance that implements the WCF Service Interface. We can use this instance to call the WCF Service.

Next let's take a look at how to call WCF

VaR factory = new common. clientfactory <imenu> (); try {var menus = factory. createclient (). getallmenu ();} catch (exception ex) {utils. alert (ex. message);} factory. dispose ();

As you can see, what interface type is used as the type parameter?

Createclient will give us feedback on what type of channel instances

We can use this channel instance to complete various behaviors described by the WCF interface.

 

Next, let's talk about the client framework form and dynamic menu ~~

 

In addition:

Xuefly has read many books ~ Strong learning ability ~

But he is also a strong racism ~ Chinese version of Hitler ~ (He must have described him as an insult to him)

Okay ~ Xuefei ~ You don't recommend me any more, so I really don't want to play with you anymore ~

---

At the same time ~ Read this articleArticleFriends ~ If you think it's interesting ~ Click here for recommendations ~~~

 

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.