Microsoft stocktrader 2.03 Study Notes (5)-sample configuration service implementation guide (1)

Source: Internet
Author: User
Tags sql management studio

The previous article mainly introduced the configuration database generation tool. This article allows us to refer to the implementation Configuration Service Guide provided by Microsoft to learn how to implement a simple custom configuration service system step by step. In this example guide, we will build a fully functional Windows Host application (which is provided by the configuration service framework base class ).ProgramIt is used to host our services, and a client application hosted in IIS to connect to this service. The Configuration Service is also implemented. All client and host applications, whether IIS-based, Windows-based, console-based, or Windows-based, can implement Configuration Services.

Step 1: Use the configuration database Generation Tool

We will use the configuration database generation tool to generate a new configuration service database. The procedure is as follows:

1. Open the configuration database generation tool.

2. Select the generate configuration database tab.

3. Enter the field information (case sensitive, same as the C # syntax ).

·Host name identifier:Tutorial service host

·Cluster Name:Tutorial service cluster

·Configuration Service namespace:Tutorial. hostconfigurationimplementation

·Settings class namespace:Tutorial. Settings

·Host environment:Windows Application

·Service host class namespace:Tutorial. Host

·Event Log Source:Tutorial service Event Log

·Node SVC virtual path:Tutorial/node

·Node SVC http port:8001

·Config SVC virtual path:Tutorial/config

·Config SVC http port:8001

·Database Server:[Your SQL Server 2005 database server name], or. \ sqlexpress locally installed SQL Server 2005 quick version

·SQL login mode:SQL Authentication

·Admin Login ID:SA

·Password:[SQL Server 2005/sqlexpress SA account password]

·Name for new configuration database:Tutorialservicerepository

4. Check the following fields before clicking the generate button.

5. Click Generate.

6. The initial configuration database is generated, and an initial Logon account "Config" and password "yyy" is used to include the connection string of your host application in the generatedCodeIn the configuration file "generatedcode/APP. config. Of course, you can also use SQL management studio to change the account password (Note: Do not forget to modify the information in APP. config if you modify the password ).

7. in addition, some other code files have been generated in the "/generatedcode" subdirectory in the same directory as the configuration database generation tool. You can use these code files to complete the following sample guide.

Step 2: Create Your Visual Studio host project

In this step, we will use the code file generated by the data generation tool configured in step 1 to complete our host implementation. You do not even need to enter any code. It is troublesome to add the correct reference for your project in the using statement in the generated code file. You may notice that not all code is generated. Most of the functions are provided by the base class provided by the configuration service framework. You can freely modify any generated code, the purpose of generating code is to allow you to quickly start your project.

1. Open Visual Studio 2005 or Visual Studio 2008 and choose to create a new C # windows project named "tutorialhost ".

2. Delete the form1.cs and program. CS files in the project.

3. Open the Properties window of the tutorialhost project.

4. Change the Assembly name to "tutorial. Host" in the project ".

5. Change the namespace to "tutorial. Host". The namespace definition here must match the Host application namespace specified in the configuration database generation tool.

6. Click the signing tab to specify a strong name for the generated assembly. The Input key file name is "tutorialhost. SNK ".

7. Close the Properties window, right-click the project, and select Add existing project.

8. Browse the \ [stocktrader installdir] \ builds \ repositorycreate \ generatedcode directory, and select the generated files program. CS, winhostconsole. CS, and App. config to add them to the project.

·Add system. runtime. serialization. dll and system. servicemodel. dll references to the project.

·Add a configuration service shared class library reference for the project. In the [stocktrader setup dir] \ sharedlibraries \ configuration directory, select the reference of the following Assembly:

Configservice. cachedatacontract

Configservice. dalsqlhelper

Configservice. iconfigactions

Configservice. runtimehostdata

Configservice. serviceconfiguration. dalfactory

Configservice. serviceconfiguration. dalsqlserver

Configservice. serviceconfiguration. idal

Configservice. serviceconfigurationbase

Configservice. serviceconfigurationcontract

Configservice. servicehostconsolebase

Configservice. servicenodecommunicationcontract

Configservice. servicenodecommunicationimplementation

Note: before completing the next two steps, you cannot compile the project.

Step 3: Create Your Visual Studio host configuration Implementation Project

In this step, we continue to use the code file generated by the tool to create the tutorial hostconfigurationimplementation project in Visual Studio.

1. Add a new C # class library project in the project and name it tutorialhostconfigurationimplementation.

2. Delete the class1.cs file.

3. Open the Properties window of the tutorialhostconfigurationimplementation project.

4. Change the Assembly name to tutorial. hostconfigurationimplementation.

5. Change the default namespace to tutorial. hostconfigurationimplementation. The namespace must match the namespace entered when the tool was just created.

6. Use the generated tutorialhost. SNK file to provide a strong name signature for the Assembly.

7. Browse the \ [stocktrader installdir] \ builds \ repositorycreate \ generatedcode directory and select the generated file configurationaction. CS and configurationservice. CS to add them to the project.

8. Add system. runtime. serialization. dll and system. servicemodel. dll references to the project.

9. Add a configuration service shared class library reference for the project. In the [stocktrader setup dir] \ sharedlibraries \ configuration directory, select the reference of the following Assembly:

Configservice. iconfigactions

Configservice. runtimehostdata

Configservice. serviceconfiguration. dalfactory

Configservice. serviceconfiguration. datacontract

Configservice. serviceconfiguration. idal

Configservice. serviceconfigurationbase

Configservice. serviceconfigurationcontract

Configservice. serviceconfigurationhelper

Configservice. serviceconfigurationutility

Configservice. servicenodecommunication. datacontract

Note: before completing the next step, you cannot compile the project.

Step 4: Create Your Visual Studio Settings Project

Next, we will create a Settings Project. The settings class in the project will contain multiple static fields. In your application, these fields are mapped to the key values that are stored in the configuration repository related to your special settings. The class generated by the tool inherits the setting base class provided by the configuration service framework. This base class provides the setting within the host range required by the configuration service for all types of applications. The following section describes how to use this class to create special settings for an application. It is worth noting that unless the content needs to be centrally loaded and managed through the Configuration Service Database (and dynamically maintained through configweb ), otherwise, you should consider storing them in the configuration file's <deleettings> Configuration section for unified load management.

1. Add a new C # class library project in the project and name it tutorialsettings.

2. Delete the class1.cs file.

3. Open the Properties window of the tutorialsettings project.

4. Change the Assembly name to tutorial. settings.

5. Change the default namespace to tutorial. settings. The namespace must match the namespace entered when the tool was just created.

6. Use the generated tutorialhost. SNK file to provide a strong name signature for the Assembly.

7. Browse the \ [stocktrader installdir] \ builds \ repositorycreate \ generatedcode directory and select the generated File Settings. CS to add it to the project.

8. Add Configuration Service shared class library reference for the project. In the [stocktrader setup dir] \ sharedlibraries \ configuration directory, select reference of the following Assembly:

Configservice. serviceconfigurationbase

9. Next we need to add the reference of the settings project to the project implemented in step 2 and step 2.

10. Add the references of the tutorial. hostconfigurationimplementation and tutorialsettings projects to the tutorialhost project.

11. Add the reference of the tutorialsettings project to the tutorialhostconfigurationimplementation project.

12. Compile the entire solution to ensure that it can be compiled now.

13.in this case, you have an executable file (tutorial.host.exe). You can run it through F5.

14. Now you can use configweb (http: // localhost/configweb) to log on to the configuration service. Enter http: // localhost: 8001/tutorial/config at the end of the configweb logon page. The logon username is localadmin and the password is yyy.

15. You can use the Windows host's config users tab or configweb to modify the password of the localadmin account.

Through the above steps, we have completed the process of configuring the host sample application of the service. Through the configuration service framework provided by Microsoft and the configuration database generation tool, it is so simple to achieve the goal. The following sections show you how to modify service configurations, add custom settings, use the main service logic service, create a client program that implements the configuration service, and generate client code and use it in Web pages. Finally, we will talk about how to use the distributed cache function provided by the configuration framework in the configuration service system.

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.