Java EE 6 SDK |
package endpoint;
import javax.jws.WebService;
@WebService
public class Hello
{
public String getHello(String name)
{
return "Hello " + name + "!";
}
}
This is as simple a Webservice as possible. All you need to create
the Webservice is one extra line:
@WebService
You can verify the Webservice is active by entering this in a browser (example server host and port):
http://localhost:8080/hello-jaxws2.2/HelloService?wsdl
${javaee.home}/bin/wsimport -Xendorsed -d ./build
http://${javaee.server.name}:${javaee.server.port}/hellojaxws2.2/HelloService?wsdl"/>
Note: the Xendorsed option since JDK 6 u4 JAXWS 2.1 is
packaged as part of rt.jar. We want to use JAXWS 2.2 apis and need to
override the JAXWS 2.1 which is part of JDK 6u4 so we need to use
Xendorsed"
package client;
import endpoint.HelloService;
import endpoint.Hello;
public class Client
{
public static void main(String[] args)
{
Client client = new Client();
client.doHello();
}
public void doHello()
{
try
{
HelloService service =new HelloService();
Hello port = service.getHelloPort();
String ret = port.getHello(System.getProperty("user.name"));
System.out.println("Hello result = " + ret);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
The client will print out a greeting from the Webservice using your
name.
Perform the following steps to build, deploy, and run the
application:
app_dir
is the sample application base
directory: samples_install_dir/javaee6/
webservices/hello-jaxws2.2
.
Change directory to app_dir.
all
target.
app_dir> ant
all
clean
to undeploy the sample
application and to
remove the temporary directories such as build and dist.
app_dir> ant
clean
Perform the following steps to build, deploy, and run the application using NetBeans IDE:
samples_install_dir/javaee6/webservices/
directory, select hello-jaxws2.2
, and click Open Project.hello-jaxws2.2
and select Run to build, deploy, and run the project.If you have problems when running the application, refer the troubleshooting document.
Copyright © 1997-2010 Oracle and/or its affiliates. All rights reserved.