Microsoft nlayerapp uses the distributed service component based on WCF to provide access interfaces and clients for external (various types of guis ).ProgramYou only need to add service references to use the functions provided by the nlayerapp. In nlayerapp, the design and structure of the distributed service is relatively simple, mainly includingDistributedservices. Core,Distributedservices. mainmoduleAndDistributedservices. DeploymentThree projects.
Distributedservices. Core
This project provides common type definitions and function implementations for all components located at the distributed service layer. For example, this project defines the fault contract type and feature (attribute) related to exception handling) definition.
Distributedservices. mainmodule
According to the requirements of the nlayerapp application, this project designs the required DTO, service contract, and operation contract, and divides them according to modules, with the partial class feature of C #, the operations of bank management, customer management, and sales management are realized respectively. The imainmoduleservice interface defines all the operation interfaces that nlayerapp's distributed service can provide, while the mainmoduleservice class implements this interface. According to the module division, the mainmoduleservice class implementation is allocated to three different files: mainmoduleservice. bankingmanagement. CS, mainmoduleservice. customersmanagement. CS and mainmoduleservice. salesmanagement. CS.
Enable imainmoduleservice. CS file, we can see that for all methods, whether it is a method parameter or return value, data transmission is implemented in the form of the original data type (primitive data types) or DTO. Nlayerapp processes domain entities as DTO at the same time. For details about DTO and domain entities as dtos, refer 《Microsoft nlayerapp case study theory and practice-Application LayerI will not talk about it here.
in the implementation class mainmoduleservice of the imainmoduleservice interface, all methods use the IOC container (I have also discussed the IOC container in detail earlier, and the nlayerapp actually uses Microsoft unity) to obtain an instance of the application layer component, to perform the corresponding operation. We can see from the above that the nlayerapp uses the IOC container in the application layer to obtain the specific implementation of the warehousing and domain service, the nlayerapp uses the IOC container between the layer and the layer to achieve stratified decoupling. The following is the implementation of the getbankaccounts method in the mainmoduleservice class Code . We can learn how to use IOC containers in distributed services.
Public list <bankaccount> getbankaccounts (bankaccountinformation) {// resolve root dependency and perform Operation ibankingmanagementservice bankingmanagement = iocfactory. instance. currentcontainer. resolve <ibankingmanagementservice> (); List <bankaccount> bankaccounts = NULL; // perform work! Bankaccounts = bankingmanagement. findbankaccounts (bankaccountinformation. bankaccountnumber, bankaccountinformation. customername); Return bankaccounts ;}
Distributedservices. Deployment
This project is actually a WCF web application, which is the host project of distributed services. It can be deployed to ASP. NET web server (such as IIS) as a web application. The mainmodule. SVC file in this project definesDistributedservices. mainmoduleMainmoduleservice class in the project), and the Web. config file configures the following information:
- Connection string used for Entity Framework
- Name of the IOC container used
- Configuration information for diagnostic and tracing programs
- Web application configuration information
- Configuration information of the WCF Service
When deploying the nlayerappDistributedservice. DeploymentDeploy the project on ASP. NET web server (such as IIS) and start the Web server. Then, the client program can access the nlayerapp application through the client configuration and proxy class of WCF.
Debugging of distributed service programs
We can use the soapui tool to debug distributed services. Soapui is an advanced open-source debugging and testing tool for Web Services. You canClick hereView the homepage of the tool and obtain the download link. Now, let's start to use soapui for debugging distributed service programs (because my system is in English, in order to avoid inaccurate translation and mislead readers, therefore, readers are advised to perform drills by referring to their Chinese version system ).
Summary
This article briefly introduces various projects involved in the distributed service of nlayerapp, and also provides a practical case to demonstrate in detail the test and debugging of the distributed service. The distributed service is the interface between the client program and the nlayerapp application. It does not contain any business logic and task coordination operations. It is only a technical implementation of communication means.
the introduction of nlayerapp is almost over. This series of articles will no longer detail the GUI part, because the development of GUI is closely integrated with specific technologies, such as WPF, sliverlight, and ASP. net MVC, readers can refer to relevant materials to read and learn, this series of articles will no longer continue on WPF, sliverlight and ASP. net MVC.