简体   繁体   中英

When generated an Apache CXF client, why is the WSDL still needed when instantiating the client?

I want to consume a SOAP service but the WSDL is provided to me offline, thus resulting in the client being generated with the local path to the WSDL.

public class SoSo extends Service {
    public final static URL WSDL_LOCATION;
    public final static QName SERVICE = new QName("http://tempuri.org/", "SoSo");
    public final static QName SoSoSoap12 = new QName("http://tempuri.org/", "SoSoSoap12");
    public final static QName SoSoSoap = new QName("http://tempuri.org/", "SoSoSoap");
    static {
        URL url = null;
        try {
            url = new URL("file:/c:/Dev/Java/workspace/service-individualreport/src/main/resources/wsdl/SoSo.wsdl");
        } catch (MalformedURLException e) {
            java.util.logging.Logger.getLogger(SoSo.class.getName())
                .log(java.util.logging.Level.INFO, 
                 "Can not initialize the default wsdl from {0}", "file:/c:/Dev/Java/workspace/service-individualreport/src/main/resources/wsdl/SoSo.wsdl");
    }
    WSDL_LOCATION = url;
}

From my point of view I would like to only build the WSDL once and then specify the location of the service.

Couple parts to this question:

1) Per JAX-WS spec, the generated code doesn't have ALL the information needed for the request. Thus, the wsdl is technically needed. With CXF, you CAN pass "null" for the wsdl URL and then use the ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost/....") to set the address and for many use cases, it will work.

2) The wsdl2java tool does have a -wsdlLocation flag that can be used to generate service objects with specific locations. -wsdlLocation "" should result in nothing burned into the code. The code wouldn't really be portable then though. (JAXWS ri/metro requires the wsdl)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM