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_want");

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 ().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

---------------------------------------------
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








Reply via email to