Java Reference
In-Depth Information
The only property you must configure for this WSDL definition bean is a builder that builds the
WSDL file from your XSD file. XsdBasedSoap11Wsdl4jDefinitionBuilder builds the WSDL file using the
WSDL4J library. Suppose that you have put your XSD file in the WEB-INF directory—you specify this
location in the schema property. This builder scans the XSD file for elements that end with the Request or
Response suffix. Then it generates WSDL operations using these elements as input and output messages,
inside a WSDL port type specified by the portTypeName property.
Because you have defined <GetTemperaturesRequest> and <GetTemperaturseResponse> in your XSD
file, and you have specified the port type name as Weather , the WSDL builder will generate the following
WSDL port type and operation for you. The following snippet is taken from the generated WSDL file:
<wsdl:portType name="Weather">
<wsdl:operation name="GetTemperatures">
<wsdl:input message="schema:GetTemperaturesRequest"
name="GetTemperaturesRequest" />
<wsdl:output message="schema:GetTemperaturesResponse"
name="GetTemperaturesResponse" />
The last property, locationUri , is for you to include this web service's deployed location in the
WSDL file. To allow an easy switch to a production URI, you should externalize this URI in a properties
file and use Spring's PropertyPlaceholderConfigurer to read the properties from it.
Finally, you can access this WSDL file by joining its definition's bean name and the .wsdl suffix.
Supposing that your service is deployed in http://localhost:8080/weather/services , this WSDL file's
URL would be http://localhost:8080/weather/services/temperature.wsdl , given that the bean name of
the WSDL definition is temperature .
5-11. Invoking Web Services Using Spring-WS
Given the contract of a web service, you can start creating a service client to invoke this service
according to the contract. You want to use Spring-WS to create the service client.
When using Spring-WS on the client side, web services can be invoked through the core template class . It's very like the JdbcTemplate class and
other data access templates in that it defines template methods for sending and receiving request and
response messages.
How It Works
Now let's create a Spring-WS client to invoke the weather service according to the contract it publishes.
You can create a Spring-WS client by parsing the request and response XML messages. As an example,
I will use dom4j to implement it. You are free to choose other XML parsing APIs for it, however.
To shield the client from the low-level invocation details, you can create a local proxy for the remote
web service. This proxy also implements the WeatherService interface, and it will translate local method
calls into remote web service calls.
Search WWH ::

Custom Search