Java Reference
In-Depth Information
How It Works
Contract-Last Web Services
In contract-last web service development, you expose an existing service interface as a web service.
There are many tools and libraries that can help expose a Java class/interface as a web service. They can
generate the WSDL file for the class/interface by applying rules, such as turning the class/interface into a
port type, turning the methods into operations, and generating the request/response message formats
according to the method arguments and return value. All in all, everything is generated from a service
interface like the following:
package com.apress.springenterpriserecipes.weather;
...
public interface WeatherService {
public List<TemperatureInfo> getTemperatures(String city, List<Date> dates);
}
This approach is called contract-last because you define the contract for this web service as the last
step in the development process by generating it from Java code. In other words, you are designing the
service with Java, not with WSDL or XML.
Contract-First Web Services
In contrast, the contract-first approach encourages you to think of the service contract first, in terms of
XML including XSD and WSDL. In this approach, you design the request and response messages for your
service first. The messages are designed with XML, which is very good at representing complex data
structures in a platform- and language-independent way. The next step is to implement this contract in
a particular platform and programming language.
For example, the request message of your weather service contains a city element and multiple
date elements. Note that you should specify the namespace for your messages to avoid naming conflicts
with other XML documents.
<GetTemperaturesRequest
xmlns=" http://springenterpriserecipes.apress.com/weather/schemas">
<city>Houston</city>
<date>2007-12-01</date>
<date>2007-12-08</date>
<date>2007-12-15</date>
</GetTemperaturesRequest>
Then the response message would contain multiple Temperature elements in response to the
requested city and dates.
<GetTemperaturesResponse
xmlns=" http://springenterpriserecipes.apress.com/weather/schemas">
<TemperatureInfo city="Houston" date="2007-12-01">
<min>5.0</min>
<max>10.0</max>
<average>8.0</average>
</TemperatureInfo>
Search WWH ::




Custom Search