1) After a dynamic client is created using a WSDL (with
JaxWsDynamicClientFactory), how do I change the URL that it's using for the web
service?
2) client.invoke() is giving me back a different class than getTypeClass() is
giving me. How do I make these match?
My code for #2 follows.
public static void main(String[] args) throws Exception {
String wsdlUrl = "http://www.webservicex.net/stockquote.asmx?WSDL";
// Select the WSI-BP compliant port
ServiceInfo serviceInfo = getServices(wsdlUrl).get(1);
QName service = serviceInfo.getName();
QName port = serviceInfo.getBindings().iterator().next().getName();
// Create the client
ClientImpl client =
(ClientImpl)JaxWsDynamicClientFactory.newInstance().createClient(wsdlUrl,
service, port);
// Get the Class for the only input message part
Class inputClass =
client.getEndpoint().getEndpointInfo().getBinding().getOperations().iterator().next().getOperationInfo().getInput().getMessageParts().get(0).getTypeClass();
System.out.println("Class: "+inputClass);
// Get the Class for the only output message part
Class outputClass =
client.getEndpoint().getEndpointInfo().getBinding().getOperations().iterator().next().getOperationInfo().getOutput().getMessageParts().get(0).getTypeClass();
System.out.println("Class: "+outputClass);
// Set the input object to request GOOGle's stock quote information
Object getQuote = inputClass.newInstance();
for (Method m : getQuote.getClass().getMethods()) {
if (m.getName().equals("setSymbol")) {
m.invoke(getQuote, "GOOG");
System.out.println(" Method: "+m.getName()+" invoked");
}
}
BindingOperationInfo boi =
client.getEndpoint().getEndpointInfo().getBinding().getOperations().iterator().next();
Object[] objects = client.invoke(boi, getQuote);
// We expect the output to be a GetQuoteResponse object, which is what
outputClass is, but it comes back as a String
for (Object o : objects) {
System.out.println("Object: "+o.getClass());
if (o instanceof String) {
String s = (String) o;
System.out.println(s);
}
}
}
public static List<ServiceInfo> getServices(String url) {
WSDLServiceFactory sf = new
WSDLServiceFactory(CXFBusFactory.getThreadDefaultBus(), url);
Definition definition = sf.getDefinition();
List<ServiceInfo> services;
services = new
WSDLServiceBuilder(CXFBusFactory.getThreadDefaultBus()).buildServices(definition);
System.out.println(services.size() + " services in Service List");
return services;
}
Thank you!
Kevin