Posted: February 7, 2012 in Random Posts

Nikos' Java blog

In the previous post we created a simple Web Service in Java. Now we’ll build on it, by providing more methods with standard argument and return types.

  • String
  • Number
  • Boolean
  • Array
  • Variable arguments

Let’s recall the Web Service with a single available operation.

@WebService
@SOAPBinding(style=Style.RPC)
public interface SimpleService {
   @WebMethod
   String sayHello();
}

Strings

Apart from sayHello, we would like a new operation that says hello to a given name.

@WebService
@SOAPBinding(style=Style.RPC)
public interface SimpleService {
   @WebMethod
   String sayHello();

   @WebMethod
   String sayHelloTo(String name);
}

Let’s implement it.

@WebService(endpointInterface="simple.SimpleService")
public class SimpleServiceImpl implements SimpleService {
   public String sayHello() {
      return "Hello from Web Services!";
   }
   public String sayHelloTo(String name) {
      return String.format("Hello %s!", name);
   }
}

If we publish the Web Service and access its WSDL, we’ll notice some new lines.

...
<message name="sayHelloTo">
   <part name="arg0" type="xsd:string"/>
</message>
...

Booleans and Numbers

Here is…

View original post 411 more words

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s