1
votes

I'm trying to develop a client for onvif which has wsdl as in:

http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl

The wsdl2java runs fine and code is generated. However, because there is no element in the wsdl, it doesn't generate a service class for me to use. It only generate an interface for the element.

The webservice's endpoint URI will be different for each device where the service is provided. My question is, given that URI, how am I supposed to get an instance of the portType interface, so that I could use the interface to interact with the webservice?

Thanks

1

1 Answers

2
votes

You don't really need it to create a service class to utilize the generated stub. It is possible to use something similar to the following:

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

...

protected <T> T getService(final Class<T> serviceClass, final boolean useSoap12) {
    final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(serviceClass);
    factory.setAddress(endpoint);
    if (useSoap12) {
        factory.setBindingId("http://schemas.xmlsoap.org/wsdl/soap12/");
    }
    return serviceClass.cast(factory.create());
}

Where serviceClass is the annotated interface CXF created.