Web service software factory (wssf) drill 2: create data contracts and implement business entities

Source: Internet
Author: User

Keywords: Web Services software factory, data contracts,Business entities

If you have missed the first part of this series, click here. You will complete the first part of the tutorial to install and set up your environment. The data contract, service contract, and business entity that you create in this section. Just like typical web services, you should focus only on your business logic and business pragmatism. To build your own WCF. We will continue to load your mycryptographyservice solution project.

Right-click the mycryptographyservice. Model Project (note that it is not a solution but a small icon below) and select Add-> new model.

Select to create a new "Data contract model" (Data contract module ). Enter mode name (Module name) as cryptographyservice. datacontracts and XML namespace (XML namespace) as http://www.cnblogs.com/LiYunQi.

You should now have a blank design area. A new data contract exploeer window appears on the right. Click the empty white design area and view the Properties window. Click Implementation Technology and select "WCF extension ".

You also need to set the project mapping table project ing table contract. This is an XML document (by default, in projectmapping. XML, it indicates that wssf acts on every project and automatically generatesCode. This file can be edited and modified ). Set the project mapping table to the mycryptographyservice we just created.

Open the Toolbox on the left and you will find some tools that adapt to the current design area, including data contract (Data contract) for serializable objects ). Used to enumerate data contract enumeration (Data contract enumeration ). The primitive data type collections (original data type) for the net data type ). Used for data contract collections (Data contract set ). Used for Abnormal Fault contracts (fault contract) and so on.

Next, you need to drag a data contract enumeration (Data contract enumeration) from the toolbox to the design area. Click the name on the top (datacontractenum1 by default) and change it to hashtype. Right-click and choose add> value to add the MD5 and sha256 enumeration respectively.

Drag another data contract to the design area and name it encryptionalgorithm1. Add two values: des and Rijndael.Algorithm. The design area should look like this when you finish.

Now, drag a "Data contract" from the toolbox to the design area. Rename hashobject and rename the list in the same way. Right-click to add a new primitive data type. The property name is "stringtohash ".

Let's take a look at the primitive data type you just added. It has the system. String and order attributes 0. We can add and modify these attributes here in the future. Now we can accept the default values.

Select the aggregation tool from the toolbox, click hashtype enumeration, hold down the mouse button, and drag to connect to hashobject. Hashobject creates a new hashtype. Set order to 1.

In the design area, your hashobject and hashtype should look like this.

You should also drag to create another "Data contract" and name it "encryptionobject. Add text Member to establish association with encryptiontype. When you finish, you should have these four objects in your design area.

Right-click any area in the blank design area and click "verify all ". There should be no errors. Otherwise, check the preceding steps.

Next, right-click some blank spaces and click "generate code ".

In the "generated code" folder of the mycryptographyservice. datacontracts Project (under the solution folder Service Interface), you will find that some class library projects have been generated. Remember that every time you change your data contract, these class library projects and automatically generated code will be overwritten.

Right-click the mycryptographyservice. businessentities Class Library Project (under the business logic solution folder) and add a class. Name it cryptographicentities. CS. In this file, we will determine the data models of all business logic entities so that they can use our solutions elsewhere. Generally, you will build the business entity layer in your own way. In this tutorial, replace the following code. Cryptographicentities. CS (except for using) is the code below.

 Namespace Mycryptographyservice. businessentities { Public Enum  Encryptionalgorithm {Des = 0, Rijndael = 1} Public Enum  Hashtype {MD5 = 0, sha256 = 1} Public class  Encryptionobject { Public String Text {Get ; Set ;} Public  Encryptionalgorithm Encryptionalgorithm { Get ; Set ;}} Public class  Hashobject { Public String Stringtohash { Get ; Set ;} Public  Hashtype Hashtype {Get ; Set ;}}}

Right-click the mycryptographyservice. serviceimplemenation project and select "create translator ".

In first class to map, select datacontracts. encryptionobject. In second class to map, select businessentities. encryptionobject. For mapping class name, enter encryptionobjecttranslator and ing Class xnl namespace to keep mycryptographyservice. serviceimplementation.

Select the text attribute in each list box and click map. Click Finish. You cannot manually modify the manually generated by the map dialog box. As long as you do not run "create translator" here, you do not have to worry about overwriting manual changes. As a matter of fact, I suggest you manually do this once your guidelines and maintenance are in place.

Repeat this process. This time we chose hashobjects. Hasing class name input hashobjecttranslator, select the graph stringtohash attribute in each list box. Next, open the code generated under the mycryptographyservice. serviceimplementation project. It should be as follows: (Please note that my namespace alias makes it short and easy to match ).

Hashobjecttranslator:

Using System; Using Mycryptographyservice. datacontracts; Using Mycryptographyservice. businessentities; Namespace Mycryptographyservice. serviceimplementation { Public static class  Hashobjecttranslator { Public static Mycryptographyservice. datacontracts. Hashobject Translatehashobjecttohashobject (mycryptographyservice. businessentities. Hashobject From) {mycryptographyservice. datacontracts.Hashobject To = New Mycryptographyservice. datacontracts. Hashobject (); To. stringtohash = from. stringtohash; Return To ;} Public static Mycryptographyservice. businessentities. Hashobject Translatehashobjecttohashobject (mycryptographyservice. datacontracts. Hashobject From) {mycryptographyservice. businessentities. Hashobject To = New Mycryptographyservice. businessentities.Hashobject (); To. stringtohash = from. stringtohash; Return To ;}}}

Encryptionobjecttranslator:

 Using System; Using Mycryptographyservice. datacontracts; Using Mycryptographyservice. businessentities; Namespace Mycryptographyservice. serviceimplementation { Public static class  Encryptionobjecttranslator { Public static Mycryptographyservice. datacontracts.Encryptionobject Translateencryptionobjecttoencryptionobject (mycryptographyservice. businessentities. Encryptionobject From) {mycryptographyservice. datacontracts. Encryptionobject To = New Mycryptographyservice. datacontracts. Encryptionobject (); To. Text = from. text; Return To ;} Public static Mycryptographyservice. businessentities. Encryptionobject Translateencryptionobjecttoencryptionobject (mycryptographyservice. datacontracts.Encryptionobject From) {mycryptographyservice. businessentities. Encryptionobject To = New Mycryptographyservice. businessentities. Encryptionobject (); To. Text = from. text; Return To ;}}}

Now you should be able to successfully generate your project and prepare for part 1. If you have any questions, please leave your comments and I will reply to you as soon as possible. Next, we will establish and implement a service contract.

Web service software factory (wssf) walkthrough 3: create a service contract and implementation method

Related Article

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.