Java Reference
In-Depth Information
@WebService public class Hello {
public String sayHello(String name) {
return "Hello, " + name";
}
}
We'll get into details throughout this chapter, but for now, this should give you an idea of the
basic programming model.
The second JAX-WS package is javax.jws.soap , which contains no classes, no interfaces,
one annotation, and four enums (there are actually four annotations in that package, but three
are deprecated and should not be used). This package is used by developers to override de-
faults with alternate values for binding to SOAP (the concrete aspect of the WSDL) when cre-
ating a web service.
Here's an example. The Hello web service will use a SOAP style, use, and parameter style of
“Document/Literal Wrapped” by default if you don't specify these three attributes otherwise.
If you want to override this, you would use the annotations in the javax.jws.soap package.
Here's an example:
package com.soacookbook;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService public class Hello {
@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE)
public String sayHello(String name) {
return "Hello, " + name";
}
}
Here you specified a non-default parameter style (the manner in which parameters will be
packaged in SOAP messages). So you indicate the only choice other than the default of “doc-
ument”, which is “bare”, and the enum will modify the generated WSDL to conform to your
wishes. Again, the details of what's happening here or why you would want to choose a “bare”
parameter style aren't important for now; this should just give you a taste of how to use this
package.
This chapter takes a close look at JAX-WS and how to use it to create web services. Enjoy!
Search WWH ::




Custom Search