views:

43

answers:

2

What are the best tools to use for generating WSDL files from Java class files?

Running into some issues using Java2WSDL and wondering what are my other options. Latest issue is that it is not encoding String[] as an array/sequence. Comes through in the WSDL as type xsd:string

By best I'm thinking - nice clean WSDL and consumed by .NET and other Java clients very easily.

A: 

My favourite method is just to use NetBeans to create a web service. Then, I use the GUI editor to define my methods, etc. and then write the code for the web service logic. NetBeans will generate a WSDL for you automatically when you browse to the http://localhost/Application/MyService?WSDL url (or you can also export one).

When I do this and define a return type as String[], the complexType produced is as follows:

<xs:complexType name="response">
  <xs:sequence>
    <xs:element name="return" type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded" /> 
  </xs:sequence>
</xs:complexType>

Which I think is what you want.

Catchwa
A: 

What are the best tools to use for generating WSDL files from Java class files?

The most straightforward way would be to annotate your Java class with JAX-WS annotations. Here is a (basic) example:

package helloservice.endpoint;

import javax.jws.WebService;

@WebService
public class Hello {
    private String message = new String("Hello, ");

    public void Hello() {}

    @WebMethod
    public String sayHello(String name) {
        return message + name + ".";
    }
}

The WSDL will be dynamically generated at runtime (but you can also generate it and deploy a static version).

See Creating a Simple Web Service and Client with JAX-WS in the Java EE Tutorials.

Pascal Thivent