7

I'd like to know if it's possible to create Web Services client from a WSDL file using Spring Web Services.

I mean from the very WSDL, I don't have any XSD for the time being.

But I've read Josh Long's "Spring Recipes A Problem-Solution Approach", Hamidreza Sattari's "Spring Web Services 2 Cookbook" and the tutorial itself (6. Using Spring Web Services on the Client) and there's no reference to this feature.

I've also read other posts, like Webservice-Client: Common approach with Spring WS, JAXB and just one WSDL file?, or Spring-ws client from WSDL (here at stackoverflow) but without any further results.

I've even asked the question at Spring forums, but no responses after more than 60 reads: Is it possible to create a WS-client from WSDL file using SWS? (It seems not)

Maybe it's not possible.

Thanks.

Community
  • 1
  • 1
jbbarquero
  • 2,842
  • 2
  • 19
  • 17
  • What do you mean when you say "create a WS-client"? Because you can use the WebServiceTemplate class to wrap anything you want in a SOAP message. I suspect that you're really thinking about creating POJO classes that the client can use. If you have a `type` section in the WSDL, then you can run that WSDL through the XJC compiler and get your classes out. – kdgregory Dec 10 '12 at 15:45
  • ¿No further results? What errors have you found in the process? What have you tried? Show some code, please. – Alfabravo Dec 10 '12 at 15:45
  • Thanks @kdgregory, what I really meant is that I want to [Send and receive POJOs: marshalling and unmarshalling](http://static.springsource.org/spring-ws/sites/2.0/reference/html/client.html#d5e1811), so XJC is what I need. Thanks to Alfabravo too, for showing interest in my issue. My only problem was to generate the POJOs as kdgregory said. I could [send a WebServiceMessage with WebServiceTemplate](http://static.springsource.org/spring-ws/sites/2.0/reference/html/client.html#d5e1787), but the static String message (for creating a StreamSource using a StringReader) wasn't what I wanted. – jbbarquero Dec 10 '12 at 23:12

1 Answers1

16

You can do it this way:

  1. Generate your java types using the xjc tool that comes with the JDK distributions - xjc -wsdl file.wsdl

  2. Then using the generated java types, use WebserviceTemplate, described here to create the client.

Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125
  • I didn't know the -wsdl option (actually I'm used to working with maven, so I usually work with some plugin as jaxb2-maven-plugin to call XJC, without further dig into details) Thanks @Biju Kunjummen for showing me the correct option. Tomorrow I will try it. – jbbarquero Dec 10 '12 at 23:18
  • You can still use the maven plugin to generate classes based on the wsdl, check out [this option](http://mojo.codehaus.org/jaxb2-maven-plugin/xjc-mojo.html#wsdl). – evandongen Jan 24 '13 at 09:31
  • Out of curiosity- do you know how to generate the xjc -wsdl command from eclipse? I created an eclipse project, right clicked on the wsdl file, and looked at the different options under the "Web Services" menu but none of them seemed right. – IcedDante Apr 01 '14 at 21:27