Escolar Documentos
Profissional Documentos
Cultura Documentos
JAX-WS
Java API for XML-Based
Web Services
Prof. Dr. Eric Dubuis
Berner Fachhochschule
Biel
Overview
01/29/08 JAX-WS 2
Why JAX-WS?
Given web services, WSDL, XML, and SOAP, JAX-WS defines ...
01/29/08 JAX-WS 4
JAX-WS Architecture
Client Service
Application Implementation
Stub / Proxy Tie
JAX-WS JAX-WS
Runtime Runtime
SOAP messages
HTTP transport
01/29/08 JAX-WS 5
Relationship between WSDL and JAX-WS
WSDL
01/29/08 JAX-WS 6
Java to WSDL Mapping
@WebService
public class StockQuoter {
public double getQuote(String symbol) throws NotFoundException {
return 123.45;
}
}
<portType name="StockQuoter">
<operation name="getQuote" parameterOrder="symbol">
<input message="tns:getQuote"/>
<output message="tns:getQuoteResponse"/>
<fault name="NotFoundException"
message="tns:NotFoundException"/>
</operation>
</portType>
01/29/08 JAX-WS 7
Developing a Web Service
Contract-first approach versus code-first
approach
A good way to get initiated into JAX-WS is to first develop a Web
service. You can develop a Web service using one of two
approaches:
01/29/08 JAX-WS 8
Developing a Web Service
«webservice»
NotFoundException
StockQuoter
01/29/08 JAX-WS 9
Developing a Web Service
@WebService(name = “StockQuoter”,
targetNamespace = “http://stocks.org”) // properties: optional
public class StockQuoter {
@WebMethod // optional
public double getQuote(String symbol)
throws NotFoundException {
...
return ...;
}
}
01/29/08 JAX-WS 10
Developing a Web Service Client
javax.xml.ws
Service
{abstract}
«use»
StockQuoter
Service
«create»
«use»
StockQuoter «interface»
NotFoundException
Client StockQuoter
01/29/08 JAX-WS 11
Developing a Web Service Client
01/29/08 JAX-WS 12
Web Service Client Using Alternate Address