Web services in Java SE, Part 2: Creating SOAP web services

Learn how to create SOAP-based Web services

1 2 3 Page 3
Page 3 of 3

Listing 8 presents the source code to a UCClient2 class that demonstrates how a client can use UC and UCImplService to access the Web service.

Listing 8. A simplified client for accessing the UC Web service

import client.UC;
import client.UCImplService;

public class UCClient2
{
   public static void main(String[] args) throws Exception
   {
      UCImplService ucis = new UCImplService();
      UC uc = ucis.getUCImplPort();
      System.out.printf("DC to DF: 37 DC = %f DF%n", uc.c2F(37.0));
      System.out.printf("CM to IN: 10 CM = %f IN%n", uc.cm2In(10));
      System.out.printf("DF to DC: 212 DF = %f DC%n", uc.f2C(212.0));
      System.out.printf("IN to CM: 10 IN = %f CM%n", uc.in2Cm(10));
   }
}

Compile Listing 8 and run the resulting application as you did with UCClient -- just make sure to replace each UCClient instance with UCClient2. You should observe the same output as shown earlier.

Conclusion

JAX-WS also supports RESTful Web services, which many developers find easier to work with than SOAP-based Web services. Part 3 of this series shows you how to build your own RESTful Web services in Java SE.

download
Get the source code for this post's applications. Created by Jeff Friesen for JavaWorld

The following software was used to develop the post's code:

  • 64-bit JDK 9ea+181

The post's code was tested on the following platform(s):

  • JVM on 64-bit Windows 8.1
1 2 3 Page 3
Page 3 of 3