开发者

Java WebServices and WSDL file generation

开发者 https://www.devze.com 2022-12-30 02:54 出处:网络
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.

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 thinkin开发者_开发知识库g - nice clean WSDL and consumed by .NET and other Java clients very easily.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消