On Friday, May 13, 2011 2:27:54 PM Kevin McClusky wrote: > Hi, > Thanks for the responses. > > For #2, how would I go about finding what the resulting class of the > client.invoke will be at runtime? (Looking to find it using programming > instead of generating a code stub and manually looking through it.)
It would also depend on "which" invoke method you use. If you use the invoke method that takes the BindingOperationInfo (which you likely already have to get the part information) instead of the one that takes the operation name, then it will use which ever form that it is expecting. If you pass the unwrapped form of the BindingOperationInfo, it will expect and return the unwrapped data. If you use the wrapped form, it will expect and return the wrapped form. That may likely be the better option for you to use. Dan > > Thanks, > Kevin > > > > ________________________________ > From: Freeman Fang <[email protected]> > To: [email protected] > Sent: Thursday, May 12, 2011 10:24 PM > Subject: Re: Two questions > > Hi, > > My comment inline > > On 2011-5-13, at 上午9:47, Kevin McClusky wrote: > > 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? > > client.getConduit().getTarget().getAddress().setValue("http://new_url_you_w > ant"); > > > 2) client.invoke() is giving me back a different class than > > getTypeClass() is giving me. How do I make these match? > > getTypeClass() will return wrapped type which is useful for jaxb to do > marshall/unmarshall, but the expected result here for client.invoke is the > String, you can use the wsdl2java tool to generate code stub from that > wsdl which you can find out the correct signature for that method. > > Freeman > > > 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().itera > >tor().next().getOperationInfo().getInput().getMessageParts().get(0).getTyp > >eClass(); System.out.println("Class: "+inputClass); > > > > // Get the Class for the only output message part > > Class outputClass = > >client.getEndpoint().getEndpointInfo().getBinding().getOperations().itera > >tor().next().getOperationInfo().getOutput().getMessageParts().get(0).getTy > >peClass(); 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().itera > >tor().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(def > >inition); System.out.println(services.size() + " services in Service > >List"); > > > > return services; > > } > > > > Thank you! > > Kevin > > --------------------------------------------- > Freeman Fang > > FuseSource > Email:[email protected] > Web: fusesource.com > Twitter: freemanfang > Blog: http://freemanfang.blogspot.com > Connect at CamelOne May 24-26 > The Open Source Integration Conference -- Daniel Kulp [email protected] http://dankulp.com/blog Talend - http://www.talend.com
