Web services development using WSCF for contractual advance

Source: Internet
Author: User
Tags wsdl

Http://www.cnblogs.com/goody9807/archive/2007/06/05/772107.html

What is contract advance (Contract-first)?

If a new software development model can affect or even change the software development process, this change is undoubtedly the most profound for developers. For many years, developers of most distributed applications have been accustomed to focusing on objects and writing a whole bunch of code from scratch. However, in the service-oriented (service-oriented) time, everything will change. From process-oriented to object-based development (Component Based Development), the field of software development has undergone time and again, and the prevalence of Web services has pushed the innovation of software methodology once again to the crest, Everything is in the spotlight of change.

There is much discussion about SOA (service-oriented architecture), both in industry and academia, called the "post-OO software Architecture", and some argue that SOA represents the direction of the future, but it is not currently suitable for large-scale industrial applications. There are also too many experts and academics in the relationship between SOA and Web services to be confused. No matter what the tide is, we have to admit that as Web services gradually become a standard protocol for the integration of distributed applications, especially heterogeneous systems, the "service autonomy, shared agreement but not shared implementation" approach to software construction has been sought after by more and more developers, which is where the contract comes from.

Developers have two choices when defining a Web Services service contract, one way is to complete the WSDL definition before the code is implemented, and here we call this development as "contract first (Contract-first)", the other way is to complete the code, Then rely on the underlying infrastructure (such as ASP. NET) to generate the contract, which we call "code first." Both of these approaches have pros and cons, but most of the development is "code-first", such as the implementation of the Web services that was written with Visual Studio.NET, and then generated by the Web services mechanism of ASP. I believe most of the developers are doing so.

The "contract first" force requires you to work with a shared language that understands WSDL, and then using WSDL directly is a tricky and uncomfortable thing for developers, because there are no particularly good tools available to support WSDL development. Traditional object-oriented technology can not directly accomplish the mapping from object to WSDL. The use of "code-first" can help to some extent the problems in "contract-first" development, as mentioned above with the use of ASP. NET-based ASMX (I believe you know what type of file) The runtime produces WSDL, another way is to use XML serialization to produce related properties. But the schema-based approach to development is optimal in the present because you can directly define service messages and data, and the result is to help your service to be more interactive and independent of the local code classes. But the biggest challenge of Schema-based's contract-first development approach is this: how to find good tools to help developers and architects complete a simplified pattern design in the design phase.

WSCF

The WSCF (Web Services Contract-first) provided by Thinktecture is a tool that simplifies the design work of the developer contract. This tool provides a number of features and features to help developers focus on the most important steps in contract-first development: Messaging and operational design. WSCF is very well integrated as a plug-in and Visual Studio 2003, so developers and architects can continue to work without leaving the custom IDE.

How to use WSCF

In the pattern-based contract development, different from the traditional programming language development, it can be divided into five steps:

1. Data modeling

The data structure is defined in this step to ensure that messages passed through the Web services interface are exchanged correctly.

2. Message Modeling

Identify the messages that need to be exchanged, such that the XML schema can be edited by XMLSpy or Vs.net's own XSD.

3. Operation and Interface modeling

Define the method actions that you want to provide to the Web services consumer

4. Generate a code skeleton

Generate platform-dependent code (such as C # or Java) based on the data, messages, and operations defined above and their interfaces.

5. Iterative contract design and code generation

Repeat the above steps

Application Scenarios

Here's a simple example of how to use WSCF for contract development

Engineering Organization

First we create an empty application solution, add three projects to the new solution, and the table below shows the purpose of each project.

Project name

Project type

Introduced

Contractmetadata

C # Blank Item

The original data definition that contains data, messages, and interfaces

Restaurantservice

C # blank Web project

Restaurant Service Web Services implementation

Restaurantclient

C # Console Project

Restaurant Service Web Services client implementation

Message and Data modeling

After adding the above project, we need to start defining the contract, as mentioned above, our first task is to create an XML schema that describes the Restautant data, and named Restautantdata.xsd, as shown in




Figure 1: Data format

At the same time, we need to define a message to exchange data



(Figure 2) for this we have added an XML schema file named Restaurantmessages.xsd, in order to be able to reference restaurantdata.xsd data, we need to manually add the code in the XSD file as shown in Figure 3


Figure 2: Message definition




Figure 3:import Syntax

Interface Contract Modeling

As mentioned at the beginning of the article, the interface contract behaves as a WSDL document, and it is obvious that no one is willing to write the WSDL first, and if you read the WSDL specification and then write it a little bit, it will be an extremely painful process, so far, There are no particularly good tools available to support the editing of WSDL documents directly, and we need a tool to define our interface protocols from a higher abstraction point of view.

WSCF provides a WSDL generation wizard, just as the ASMX runtime does, as far as possible the technical details of the WSDL specification are hidden from the developer and the schema, and the following table shows the current string pattern support for WSCF operation references, simply speaking, WSCF can automatically infer some actions based on the message definition provided by the XSD.

Input message

Output message

Inference action

Xyz

XYZResponse

Xyz

XYZRequest

XYZResponse

Xyz

Zyzrequestmessage

XYZresponsemessage

Xyz

Finally, WSCF supports some simple WSDL iterations, which means that you can generate a WSDL document from the build-view-modify--and let's take a look at how the WSCF Wizard generates the WSDL document.




Figure 4: Generating a WSDL document using WSCF

By clicking on the right-click menu in the restaurantmessage.xsd we can see the 4 interface, start the wizard and follow the wizard's request to complete the operation, this time produced the WSDL document we need, this is the most critical step of contract development, 5, we have been named "RESTAURANTSERVICE.WSDL" document, then the rest of the work is to start producing the code.



Figure V: Contractmedadata file layout

Generate code from contract

Here we discuss only the build. NET platform, the following code, for other platforms such as Java, provides conversion from WSDL to Java code, interested readers can refer to eclipse or other Java de related documents. As shown in 6, WSCF supports generating clients and servers




The Code

We can generate the relevant program code as needed, then the actual business situation to achieve the specific business details. The generated part of the code is shown below

public class Restaurantinfo

{

private string name;

public string Name

{

Get

{

return this.name;

}

Set

{

THIS.name = value;

}

}

}








Other

At the same time WSCF provides a command-line tool "Wscf.exe", which is a command-line-based code generation engine that can be wscf.exe–help to view detailed parameter usage information.

Summary

With the demonstration above we can see how to use XSD and WSCF to implement contract-first development, of course, do not expect to be able to do all the work for you through a tool, WSCF only in the generation of WSDL and code generation to provide a simplified way to use, as to how the "code First" and "contract first "The choice is based on your specific application, and in general, the development of" contract first "is preferred in the following scenario

1) Neither the client nor the server segment has implemented code, and the contract changes are present

2) The client and server segments are heterogeneous and simply say that the client and server segments may be implemented in different platforms, such as clients using Java, and server-side using. NET

3) System interoperability scenarios are more complex

Web services development using WSCF for contractual advance

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.