Microsoft nlayerapp case study theory and practice-distributed service

Source: Internet
Author: User
Tags soapui

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 ).

  • Nlayerapp compiled
  • Under the distributedservices. Deployment project, right-click the mainmodule. SVC file and choose View in browser. This starts ASP. NET development server and displays the following page in IE:

  • Start soapui. In the navigator panel, right-click the projects node and choose new soapui project. The new soapui project dialog box is displayed. In the initial WSDL/wadl text box, enter http: // localhost: 88/mainmodule. SVC? WSDL. In this case, the Project Name text box is automatically filled with "mainmodule". If you do not care about other options, click OK.

  • Expand the mainmodule node in the navigator panel. We can see that it contains two endpoints: ws2007forintranetclients and basicbindingforsliverlightclients.Distributedservices. DeploymentThe configuration in Web. config of the project is consistent.

  • Expand the basicbindingforsliverlightclients node to view all the methods released by the imainmoduleservice interface. Expand the getcustomerbycode operation and double-click request 1. In the open request 1 dialog box, the left part lists the SOAP envelope that calls this operation.

  • On the node, enter a0001. the following request XML is obtained:
     
         
           xmlns: MIC =" Microsoft. samples. nlayerapp. distributedservices. mainmoduleservice "> 
           
           
            
             
            
              a0001 
             
            
           
          

  • Click the green arrow in the upper-left corner of the request 1 dialog box to call the getcustomerbycode method and obtain the returned results.

  • To debug the distributed service, set the breakpoint, select debug> attach to process in Visual Studio, and select ASP in the attach to process dialog box that appears. net Development Server-port 88, and then click attach, which enables Visual Studio to enter the debugging mode

  • Click the green arrow in the request 1 dialog box to call the distributed service. The program execution stops at the breakpoint for developers to debug.
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.

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.