This will connect to the provided URL
and attempt
to use the cd-catalog-demo web service to get a listing
of currently available CDs. It then outputs that list to
System.out
.
System.out.println("Listing current CD catalog.");
// Map the CD type so SOAP can use it
SOAPMappingRegistry registry = new SOAPMappingRegistry();
BeanSerializer serializer = new BeanSerializer();
registry.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("urn:cd-catalog-demo", "cd"),
CD.class, serializer, serializer);
// Build the Call object
Call call = new Call();
call.setSOAPMappingRegistry(registry);
call.setTargetObjectURI("urn:cd-catalog");
call.setMethodName("list");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// No parameters needed
// Invoke the call
Response response;
response = call.invoke(url, "");
if (!response.generatedFault()) {
Parameter returnValue = response.getReturnValue();
Hashtable catalog = (Hashtable)returnValue.getValue();
Enumeration e = catalog.keys();
while (e.hasMoreElements()) {
String title = (String)e.nextElement();
CD cd = (CD)catalog.get(title);
System.out.println(" '" + cd.getTitle() + "' by " + cd.getArtist() +
" on the label " + cd.getLabel());
}
} else {
Fault fault = response.getFault();
System.out.println("Error encountered: " + fault.getFaultString());
Vector entries = fault.getDetailEntries();
for (Iterator i = entries.iterator(); i.hasNext(); ) {
org.w3c.dom.Element entry = (org.w3c.dom.Element)i.next();
System.out.println(entry.getFirstChild().getNodeValue());
}
}