Code first vs WSDL frist

Source: Internet
Author: User

To build a web service, cxf provides two construction methods: code first and WSDL first.
So what is code first and what is WSDL first?

As you know, if we want to publish a WebService to a service, we need to define the methods supported by this service, and call the parameters provided by these methods and convert them into WSDL, for other clients to call. Code first is a way to build WebService provided by the first generation of WebService development tools. Taking Java as an example, we can define the methods provided by a set of web services through interfaces. Code first constructs the information required by web services by obtaining the information of this interface, and generate the WSDL based on the information.

While WSDL first generates related aritifacts through the WSDL file, such as related interfaces and implementedCodeFramework, etc. This is the same as the development of CORBA. We first use IDL to describe our CORBA service and use idl2xxx to generate related interfaces and implementation frameworks (blocking the operations of Marshal and unmarshal in network transmission ).

These two types of web services have their own characteristics and are suitable for different scenarios.

Friends who have been familiar with WSDL should have this feeling. Although WSDL is described in XML, if you want to write a correct WSDL without using any tools, or it is very difficult to correct a wrong WSDL. Code first can be said to provide us with a good choice.

However, the best practies of Web Services does not recommend the code first Web Services construction method. Why?

This is because when we build code first, we seldom take into account that the interaction between Web Services is conducted in document mode (this can greatly improve the interaction between Web Services ), if code first is used to construct the WSDL information, the XML schema that describes the interaction information is generated based on the type information defined in our code, in this way, some fine-grained information may be exposed. At the same time, we know that different languages (C ++, Java, C #, PHP) have different XML Schema mappings. If the types defined in the Code are special, it may lead to a phenomenon that cannot interoperate.

Therefore, best practies recommends that you create a web service to start with the interactive message schema and build an intermediate layer to provide a coarse-grained description, which can better solve the problem of mutual interaction between Web Services.

From: http://willem.bokeland.com/blog/794/post/trackbacks/108854

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.