Chapter 2. All About WSDLs

What Good Is a WSDL?

The usefulness of WSDLs, the service contracts for SOAP-based web services, is shown best through examples. The original Java client against the TimeServer service invokes the Service.create method with two arguments: a URL, which provides the endpoint at which the service can be accessed, and an XML-qualified name (a Java QName), which in turn consists of the service’s local name (in this case, TimeServerImplService) and a namespace identifier (in this case, the URI http://ts.ch01/). Here is the relevant code without the comments:

URL url = new URL("http://localhost:9876/ts?wsdl");
QName qname = new QName("http://ts.ch01/", "TimeServerImplService");
Service service = Service.create(url, qname);

Note that the automatically generated namespace URI inverts the package name of the service implementation bean (SIB), ch01.ts.TimeServerImpl. The package ch01.ts becomes ts.ch01 in the URI. This detail is critical. If the first argument to the QName constructor is changed to the URI http://ch01.ts/, the Java TimeClient throws a exception, complaining that the service’s automatically generated WSDL does not describe a service with this namespace URI. The programmer must figure out the namespace URI—presumably by inspecting the WSDL! By the way, even the trailing slash in the URI is critical. The URI http://ts.ch01, with a slash missing at the end, causes the same exception as does http://ch01.ts/, with ch01 and ts in the wrong order.

The same point ...

Get Java Web Services: Up and Running now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.