JAX-WS client without a WSDL document file
Asked Answered
K

4

13

I am consuming a webservice soa, with netbeans (jax-ws) i use netbeans auto generate client, and all run fine, but i see that the wsdl is always downloading while the client is running.

In production i don't want expose the wsdl, and i am trying to modify the client for don't require wsdl, all my intends are wrong, i find this:

WebService_Service svc = new WebService_Service(
  null,
  new QName("http://www.example.com/ws", "WebService"));
WebService port = svc.getPort(WebService.class);
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
  .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
    "http://www.example.com/real_endpoint_url_goes_here");

but when the first line is executed i found this exception:

Message: El contenido no está permitido en el prólogo.
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(Unknown Source)
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(Unknown Source)
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(Unknown Source)
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(Unknown Source)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.hasWSDLDefinitions(Unknown Source)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
    at javax.xml.ws.Service.<init>(Unknown Source)

Any idea to ignore wsdl?

Kroll answered 6/11, 2013 at 14:49 Comment(1)
finally i migrate the client to CXF, and all work fineKroll
K
6

Finally i use the CXF libraries and i achieve use the Paul Vargas answer:

Without a WSDL document file

This solution requires the client generated.

QName qname = new QName("http://thenamespace", "FooService");
FooService service = new FooService(null, qname); // null for ignore WSDL
Foo port = service.getFooPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
    .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
    "http://foo.com/soap/fooBean");

// Use the service
String result = port.doSomething(param);

Using standard jaw-ws, this solution don't work, CXF is necessary.

Kroll answered 23/12, 2013 at 8:51 Comment(0)
W
22

There are several ways, of which I will tell you two:

  1. Use a WSDL document file locally

    Save a copy of the WSDL document file and the schemma files to your project.

    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    URL wsdlLocation = classloader.getResource("MyHelloService.wsdl");
    QName serviceName= new QName("http://test.com/", "MyHelloService");
    
    MyHelloService service = new MyHelloService(wsdlLocation, serviceName);
    service.sayHello("Test");
    

    You may combine the WSDL document file with the schema files.

  2. Without a WSDL document file

    This solution requires the client generated.

    QName qname = new QName("http://thenamespace", "FooService");
    FooService service = new FooService(null, qname); // null for ignore WSDL
    Foo port = service.getFooPort();
    BindingProvider bindingProvider = (BindingProvider) port;
    bindingProvider.getRequestContext()
        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
        "http://foo.com/soap/fooBean");
    
    // Use the service
    String result = port.doSomething(param);
    
Wellborn answered 7/11, 2013 at 3:23 Comment(4)
Thaks for the answer i am trying to use the way number 2, but i have the exception to the first post (the question)Kroll
I tried to summarise this all up in a post here: medium.com/@nieldw/…Multiversity
I had a similar problem and wanted to combine this with Dispatch, which didn't work for Apache CXF in this case. What helped a lot was some old IBM docu: ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/…Wilford
I tried the 2nd solution but it doesn't ignore the wsdl. It attempts to use the wsdl from it's original location from which I generated the classes with wsimport. Ended up using the 1st solution and saving the wsdl in the source codeAmadaamadas
K
6

Finally i use the CXF libraries and i achieve use the Paul Vargas answer:

Without a WSDL document file

This solution requires the client generated.

QName qname = new QName("http://thenamespace", "FooService");
FooService service = new FooService(null, qname); // null for ignore WSDL
Foo port = service.getFooPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
    .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
    "http://foo.com/soap/fooBean");

// Use the service
String result = port.doSomething(param);

Using standard jaw-ws, this solution don't work, CXF is necessary.

Kroll answered 23/12, 2013 at 8:51 Comment(0)
C
1

I needed something like this, too.

In my case, I had put a dummy wsdl without endpoint address inside my web app classpath. After that, I set a valid address at runtime, like this:

    String WSDL = "/config/ws/Main_default.wsdl";
    Main service = new Main(Main.class.getResource(WSDL), new QName(
            "http://www.example.com/", "Main"));
    MainWS port = service.getMainWSPort();

    BindingProvider bindingProvider = (BindingProvider) port;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://app.example.com/ws/services/main");

    Object result = port.someMethod("some param");
Castorena answered 15/9, 2014 at 19:25 Comment(1)
confirm that this solution works with jax-ws, thanksLiegnitz
C
0

This exception happens while there is a parse error in your xml and there is something wrong at the specified row and column. Check your xml

Cracked answered 6/11, 2013 at 18:35 Comment(5)
Yes, i think that the exception ocurrs because i am pass null to service constructor and it try to download the wsdl and not find anything. but i don't know how force client to not download the wsdlKroll
try using no arg constructor WebService_Service svc = new WebService_Service()Cracked
thaks for the answer, but in this case, default constructor call to wsdl because have inside one reference to it. i try to deleted the inside reference to wsdl, but the problem persist. it s not posible use client without wsdl?Kroll
Are you using cxf or axis?With cxf the mentioned method worksCracked
i am using the default libraries that comes with netbeans (jax-ws) i follow this tutorial: martcode.com/tipsGallery/…Kroll

© 2022 - 2024 — McMap. All rights reserved.