I am doing some research on web services. I have not written any web service but I am doing a small write up on them.
During my research I've come across terms contract-first and contract-last.
Can someone explain these two in an understandable form ?
In a contract-first approach, you start development by defining the contract, or the 'interface' of the service. In the code-first approach you start development from code and then create the contract. Software that is designed using interfaces hides implementation details and promotes code reuse.
The Contract-first approach tells us to create first WSDL and then create end-point interface and implementation class. The Contract-last approach tells us to create first end-point interface and implementation class then create WSDL file.
In the contract-first web service, the “contract” (a WSDL definition of operations and endpoints and XML schema of the messages) is created first, without actually writing any service code. In the contract-last web service, existing logic is “exposed” as a web service and the contract is created at the very end.
WSDL contracts define services using Web Service Description Language and a number of possible extensions. The contracts have a logical part and a physical part. The abstract part of the contract defines the service in terms of implementation neutral data types and messages.
To expound on the answer by Kaleb, contract-first is where you create the WSDL, and then you can create the implementation from this, and since the WSDL is your contract, this would be contract-first.
Contract-last is where the WSDL is created from the source code, or implementation, so it will most likely be generated by a tool rather than created by the developer.
Update:
For a nice explanation with code, in Java, you can look at this explanation from the Spring Web Services 1.5 documentation.
They will discuss the pros and cons, though they will be biased toward their approach (which is contract-first). Anyway, I think it is a nice explanation.
Contract-first means you design the way your services are going to communicate with each other before you design the services themselves.
Contract-last is the other way around – you design how your service is going to work, then make one or more methods available as the interface for other services.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With