WSIFPort port = null;
port = service.getPort(portName);
WSIFOperation operation =
port.createOperation("addEntry", "AddEntryWholeNameRequest", null);
WSIFMessage inputMessage = operation.createInputMessage();
WSIFMessage outputMessage = operation.createOutputMessage();
WSIFMessage faultMessage = operation.createFaultMessage();
// Create a name and address to add to the addressbook
String nameToAdd = "Chris P. Bacon";
Address addressToAdd =
new Address(
1,
"The Waterfront",
"Some City",
"NY",
47907,
new Phone(765, "494", "4900"));
// Add the name and address to the input message
inputMessage.setObjectPart("name", nameToAdd);
inputMessage.setObjectPart("address", addressToAdd);
// Execute the operation, obtaining a flag to indicate its success
operation.executeInputOnlyOperation(inputMessage);
// Start from fresh
operation = null;
inputMessage = null;
outputMessage = null;
faultMessage = null;
operation = port.createOperation("getAddressFromName");
// Create the messages
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
// Set the name to find in the addressbook
String nameToLookup = "Chris P. Bacon";
inputMessage.setObjectPart("name", nameToLookup);
// Execute the operation
boolean operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
if (operationSucceeded) {
System.out.println(
"Successfull lookup of name '" + nameToLookup + "' in addressbook");
// We can obtain the address that was found by querying the output message
Address addressFound = (Address) outputMessage.getObjectPart("address");
System.out.println("The address found was:");
System.out.println(addressFound);
} else {
System.out.println("Failed to lookup name in addressbook");
}
// Check that we can't reuse an operation.
boolean caughtException = false;
try {
operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
} catch (WSIFException we) {
caughtException = true;