Creating a Simple JAX-WS WebService in Eclipse

I am trying to create a simple web service in eclipse. First I created an empty java project and added the following three files to the src folder

  • Greeting.java
package com.alfaisaliah; import javax.jws.WebService; import javax.jws.WebMethod; @WebService public interface Greeting { @WebMethod String sayHello(String name); } 
  1. GreetingImp.java
 package com.alfaisaliah; import javax.jws.WebService; @WebService(endpointInterface="com.alfaisaliah.Greeting") public class GreetingImp implements Greeting { @Override public String sayHello(String name) { return "Hello " + name; } } 
  1. Wspublisher
 package com.alfaisaliah; import javax.xml.ws.Endpoint; public class WSPublisher { public static void main(String[] args){ Endpoint.publish("http://localhost:8081/WS/Greeting", new GreetingImp()); } } 

The following tutorial does not specify a server to run a web service! I am wondering if any server needs to be specified. I already have Tomcat v5.5, but I do not use it in this example. Whenever I run this project as a java project, I get some error. Can someone help me determine where my problem is trying to start the web service. Here is the output of the eclipse console

 Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass INFO: Dynamically creating request wrapper Class com.alfaisaliah.jaxws.SayHello Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass INFO: Dynamically creating response wrapper bean Class com.alfaisaliah.jaxws.SayHelloResponse 

Also, when I start the project again, it says that the address is already in use

 Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass INFO: Dynamically creating request wrapper Class com.alfaisaliah.jaxws.SayHello Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass INFO: Dynamically creating response wrapper bean Class com.alfaisaliah.jaxws.SayHelloResponse Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Address already in use 

I would be grateful for your help to the guys :)

+4
source share
2 answers

check this link

http://www.myeclipseide.com/documentation/quickstarts/webservices_jaxws/

The link above provides step-by-step details for creating a server and web service client.

You start with POJO, without the need for annotations, the JAX-WS runtime will take care after deployment to the Tomcat server.

+2
source

The tutorial that I am running does not point the server to launch website maintenance on! I am wondering if any server needs to be specified.

You do not need a server with this code.
Your main in:

 Endpoint.publish("http://localhost:8081/WS/Greeting", new GreetingImp()); 

launches a lightweight HTTP server under the hood (available after JKD 1.6), and it deploys your web service, handling all incoming / outgoing traffic.

The problem is that you skipped the step:
You must generate the necessary artifacts using the wsgen tool (available in java).

Check out here: JAX WS Tutorial for
wsgen -d build -s build -classpath build helloservice.endpoint.Hello
and read about wsgen .

Honestly, I don’t remember how you do it through Eclipse (in fact, I’m not sure that this can work in Eclipse automatically, without having to run wsgen yourself), but you can run it manually and just copy the created artifacts in your project .

Concerning

Server runtime error: java.net.BindException: address is already in use

This is self-evident: just use a different port. 8081 is already in use.

+4
source

Source: https://habr.com/ru/post/1398449/


All Articles