WebServices TY 1
WebServices TY 1
A simple definition:
1. publish 2. find
Service
3. bind/invoke
Service
Provider Client
Webservices Characteristics(Based
on SOA)
Distributed Computing
Internet Protocols
Middleware
Client–server model
Messaging
No Step Description
1 Import the standard JWS The standard JWS annotations are in either
annotations that will be used in the javax.jws or javax.jws.soappackage. For
your JWS file. example:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
2 Import additional annotations, as
required.
3 Add the standard
required @WebService JWS
annotation at the class level to
specify that the Java class exposes
a Web Service.
No Step Description
4 Add the In particular, use this annotation to specify
standard @SOAPBinding JWS whether the Web Service is document-literal,
annotation at the class level to document-encoded, and so on. Although this
specify the mapping between the JWS annotation is not required, Oracle
Web service and the SOAP recommends you explicitly specify it in your
message protocol. (Optional) JWS file to clarify the type of SOAP bindings a
client application uses to invoke the Web
Service.
No Step Description
5 Add the JAX-
WS @BindingType JWS annotation
at the class level to specify the
binding type to use for a Web
Service endpoint implementation
class. (Optional)
6 Add the Optionally specify that the operation takes
standard @WebMethod annotation only input parameters but does not return any
for each method in the JWS file value by using the
that you want to expose as a standard @Oneway annotation.
public operation. (Optional)
No Step Description
7 Add @WebParam annotation to customize
the name of the input parameters of the
exposed operations. (Optional)
Use the standard @WebService annotation to specify, at the class level, that the JWS file
implements a Web Service, as shown in the following code excerpt:
@WebService(name="SimpleWS",
serviceName="SimpleService",
targetNamespace="http://example.org")
In the example, the name of the Web Service is SimpleWS, which will later map to
the wsdl:portType element in the WSDL file generated by the jwsc Ant task. The service name
is SimpleService, which will map to the wsdl:service element in the generated WSDL file. The
target namespace used in the generated WSDL is http://example.org.
You can also specify the following additional attributes of the @WebService annotation:
– endpointInterface—Fully qualified name of an existing service endpoint interface file. This annotation
allows the separation of interface definition from the implementation. If you specify this attribute,
the jwsc Ant task does not generate the interface for you, but assumes you have created it and it is in
your CLASSPATH.
– portname—Name that is used in the wsdl:port.
None of the attributes of the @WebService annotation is required.
Specifying the Mapping of the Web Service to the SOAP
Message Protocol (@SOAPBinding Annotation)
Use the JAX-WS @BindingType annotation to customize the binding to use for a web service
endpoint implementation class, as shown in the following code excerpt:
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;
public class Simple { @WebService()
@BindingType(value=SOAPBinding.SOAP12HTTP_BINDING)
public int echoInt(
@WebParam(name="IntegerInput",
targetNamespace="http://example.org/docLiteralBare")
int input) {
System.out.println("echoInt '" + input + "' to you too!");
return input;
}
... In the example, the deployed endpoint would use the SOAP1.2 over HTTP binding. If not specified, the binding defaults to SOAP 1.1 over HTTP.
You can also specify the following additional attributes of the @BindingType annotation:
– features—An array of features to enable/disable on the specified binding. If not specified, features are
enabled based on their own rules.
Rules for methods on classes
annotated with @WebService
The following rules apply for methods on classes annotated with the @WebService
annotation.
If the @WebService annotation of an implementation class references an SEI, the
implementation class must not have any @WebMethod annotations.
All public methods for an SEI are considered exposed methods regardless of
whether the @WebMethod annotation is specified or not. It is incorrect to have an
@WebMethod annotation on an SEI that contains the exclude attribute.
For an implementation class that does not reference an SEI, if the @WebMethod
annotation is specified with a value of exclude=true, that method is not exposed. If
the @WebMethod annotation is not specified, all public methods are exposed
including the inherited methods with the exception of methods inherited from
java.lang.Object.
The basic steps for creating a web service
and client are as follows:
/**
* The @WebService property endpointInterface links the
* SIB (this class) to the SEI (ts.TimeServer).
* Note that the method implementations are not annotated
* as @WebMethods.
*/
@WebService(endpointInterface = "ts.TimeServer")
public class TimeServerImpl implements TimeServer {
public String getTimeAsString() { return new Date().toString(); }
public long getTimeAsElapsed() { return new Date().getTime(); }
}
Publish the Web Service
Once the SEI and SIB have been compiled,
2 Backroads Lane
New York
045935435
[email protected]
HTML specifies how the document is to be
displayed, and not what information is contained
in the document.
Hard for machine to extract the embedded
XML vs HTML
Now look at the following:
<?xml version=1.0?>
<contact>
<name>John Doe</name>
<address>2 Backroads Lane</address>
<country>New York</country>
<phone>045935435</phone>
<email>[email protected]</email>
</contact>
In this case:
– The information contained is being marked, but not for
displaying.
– Readable by both human and machines.
SOAP
SOAP originally stood for "Simple Object Access
Protocol" .
Web Services expose useful functionality to Web users
through a standard Web protocol called SOAP.
Soap is an XML vocabulary standard to enable
programs on separate computers to interact across any
network. SOAP is a simple markup language for
describing messages between applications.
Soap uses mainly HTTP as a transport protocol. That
is, HTTP message contains a SOAP message as its
payload section.
SOAP Characteristics
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle=http://www.w3.org/2001/12/soap-encoding”>
<soap:Body xmlns:m="http://www.stock.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
SOAP Response
HTTP/1.1 200 OK
Content-Type: application/soap; charset=utf-8
Content-Length: 126
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.stock.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
SOAP Security
Definition
TargetNamespace
DataTypes
Messages
Porttype
Bindings
service
The WSDL Document Structure
<portType name=“StocksRates">
<operation name=“GetStockPrice">
<input message=“GetStockPriceRequest"/>
<output message=“GetStockPriceResponse"/>
</operation>
</portType>
WSDL Structure
The main structure of a WSDL document looks like this:
<definitions>
<types>
definition of types........
</types>
<message>
definition of a message....
</message>
<portType>
<operation>
definition of a operation.......
</operation>
</portType>
<binding>
definition of a binding....
</binding>
<service>
definition of a service....
</service>
</definitions>
Sections of WSDL
https://www.ibm.com/developerworks/library/
ws-whichwsdl/
Disadvantages of RPC style
The WSDL, with its empty types section, does not provide an XSD against which
the body of a SOAP message can be validated.
The service cannot use arbitrarily rich data types because there is no XSD to
define
such types. The service is thus restricted to relatively simple types such as
integers,strings, dates, and arrays of such.
This style, with its obvious link to the request/response pattern, encourages tight
coupling between the service and the client.
Java services written in this style may not be consumable in other frameworks,
thus undermining interoperability. Further, long-term support within the web
The body of a SOAP message can be validated against the XSD in the
types section of the WSDL.
A service in this style can use arbitrarily rich data types, as the XML
Schema language supports not only simple types such as integers,
strings, and dates, but also arbitrarily rich complex types.
There is great flexibility in how the body of a SOAP message is structured
so long
as the structure is clearly defined in an XSD.
The wrapped convention provides a way to enjoy a key upside of the rpc
style—
naming the body of a SOAP message after the corresponding service
operation—
without enduring the downsides of the rpc style
Disadvantages of Document style
In the unwrapped variant, the SOAP message does not carry the name of
the service operation, which can complicate the dispatching of messages
to the appropriate program code.
The wrapped variant adds a level of complexity, in particular at the API
level.
Writing a client against a wrapped-document service can be challenging.
The wrapped variant does not support overloaded service operations
because the
XML wrapper element in the body of a SOAP message must have the
name of
the service operation. In effect, then, there can be only one operation for
a given
element name.
Code First Versus Contract First
One-way
The service receives a message. The
operation therefore has a single input element.
The grammar for a one-way operation is:
<wsdl:definitions .... > <wsdl:portType .... > *
<wsdl:operation name="nmtoken"> <wsdl:input
name="nmtoken"? message="qname"/>
</wsdl:operation> </wsdl:portType >
</wsdl:definitions>
WSDL Patterns of Operation
Request-response
The service receives a message and sends a response. The
operation therefore has one input element, followed by one output
element. To encapsulate errors, an optional fault element can also
be specified. The grammar for a request-response operation is:
<wsdl:definitions .... > <wsdl:portType .... > *
<wsdl:operation name="nmtoken" parameterOrder="nmtokens">
<wsdl:input name="nmtoken"? message="qname"/> <wsdl:output
name="nmtoken"? message="qname"/> <wsdl:fault
name="nmtoken" message="qname"/>* </wsdl:operation>
</wsdl:portType > </wsdl:definitions>
WSDL Patterns of Operation
Solicit-response
The service sends a message and receives a response. The
operation therefore has one output element, followed by one input
element. To encapsulate errors, an optional fault element can also
be specified. The grammar for a solicit-response operation is:
<wsdl:definitions .... > <wsdl:portType .... > * <wsdl:operation
name="nmtoken" parameterOrder="nmtokens"> <wsdl:output
name="nmtoken"? message="qname"/> <wsdl:input
name="nmtoken"? message="qname"/> <wsdl:fault
name="nmtoken" message="qname"/>* </wsdl:operation>
</wsdl:portType > </wsdl:definitions>
WSDL Patterns of Operation
Notification
The service sends a message. The operation therefore
has a single output element. Following is the grammar
for a notification operation:
<wsdl:definitions .... > <wsdl:portType .... > *
<wsdl:operation name="nmtoken"> <wsdl:output
name="nmtoken"? message="qname"/>
</wsdl:operation> </wsdl:portType >
</wsdl:definitions>
UDDI
<service>
BusinessService
<port>
<port>
BindingTemplate
BindingTemplate
Service Interface
<types>
<message>
tModel
<portType>
<binding>
What is UDDI?
– Directory service where businesses can register and search
for Web services
Directory for storing information about web services
Directory of web service interfaces described by WSDL
– UDDI communicates via SOAP
What is UDDI Based On?
– Uses W3C Internet standards such as XML, HTTP, and DNS
protocols
– UDDI uses WSDL to describe interfaces to web services
How can UDDI be Used?
UDDI Benefits