Contract-first, the key of service-oriented

Source: Internet
Author: User

Speaking of "contract-first", we should first add this sentence: "services share schema and contract, not class ".

Contract-first is definitely one of the most important principles and concepts in designing a service-oriented system. If you want to develop a service-oriented stuff, one of the keys to understanding is contract-first. The interface exposed by the service should be a contract, which serves as its own explanation: "What services can I provide and what parameters are required for these services, which values will be returned... "If data needs to be transmitted between services, there must also be a contract recognized by the service and client. This contract is used to describe:" The data we want to transmit, the first is a string that contains name information, and the second is an integer that contains age information... because services usually use soap packets for communication, contract must be used to describe information such as the encoding format of soap packets.

Although N people are already posting "WebService! = Soa ", but I still need to talk about it with WebService first. How can we use the contract-first concept to build a WebService? We need to first define the contract (Data contract) for the data to be exchanged. XSD is used to define the data schema. Then, let's define the contract (Message contract) of the message for communication between the service and the client. Don't forget that messsage-based is one of the basic features of service-oriented. Next, based on the data contract and message contract defined by XSD, generate our description file WSDL. WSDL describes the service interface and the data structure it uses. From the WSDL, we can generate the actual class code file to support development.

We can see that the design concept of contract-first is quite different from the method we use to build WebService. Contract-first is to first determine the various contract, Data, message, and interface for the service to interact with the client, rather than writing the actual class code first, then add "[webmethod]" to it to make it a WebService interface.

Wscf is a tool that supports the concept of contract-first to design WebService. It is a plug-in of vs. NET and can easily support the methods and steps described above to build WebService.

The benefit of using contract-first to build WebService is that contract is independent, portable, and out of code. Since we can use XSD to describe contract, we only need to share these XSD description files with other services, so services can share these contract. We no longer need another service to reference an Assembly containing the person object, so that the other service can exchange the person data. On the contrary, we only need to share the data contract describing the person structure to the other service, even if the other service may be implemented in Java, they can also generate actual support code on their platforms based on these data contract and exchange person data with local services in a contract-compliant manner.

The following is from wscf:

Defined data contract:

Defined message contract:

Contract is described by the XSD file:

Finally, contract automatically generates the WSDL description file, and then generates the actual support code from the WSDL:

As you can see, the above method is completely different from the traditional code-> Add [webmethod]-> automatically by. asmx? To generate a WSDL.

After talking about this, I turn to Indigo. Indigo has released the first public version of CTP, so it is time to write indigo in the blog. Indigo is a development framework used by Microsoft to build the connected system. The entire architecture conforms to the concept of service-oriented. Therefore, contract-first is also one of the basic concepts of indigo.

The following is a data contract example in Indigo. [datacontractattribute] is used in indigo to identify data contract:

[Datacontract]
Public class person
{
[Datamember]
Public string name;
[Datamember]
Public datetime birthday;
}

The following is an example of the indigo service interface, which uses attribute to identify service contract and service operation contained in service contract:

[Servicecontract]
Public interface ipersonservice
{
[Operationcontract]
Person getperson (string name );
[Operationcontract]
Void updateperson (person );
}

Public class personservice: ipersonservice
{
...
}

The next blog will introduce indigo.

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.