M. Carlo Bramini
M. Carlo Bramini

Reputation: 2522

Java: WSDL web service wsimport, do I need to re-run wsimport of I change the @WebService class code in the webservice server

I'm building a webservice with a java client and a java webservice on Glassfish running on Windows Werver 2012.

This is my @WebService class:

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;

@WebService
public class ProductCatalog {

    public List<String> getProductCategories(){
     List<String> categories = new ArrayList<>();
     categories.add("Books");
     categories.add("Music");
     categories.add("Movies");

     return categories;
   }
}

On the client side to create the stub method I use wsimport conversion that is in java to generate the required java source files comming from the WSDL xml issued by the WS.

What I have noticed is that, if I add a cetgory to to the list:

     //...code
     categories.add("Books");
 categories.add("Music");
 categories.add("Movies");
 categories.add("Pens");
     //...code

I get from the client side the updated arraylist: Book,Music,Movie + "Pens"

thanks Luther

Upvotes: 0

Views: 1600

Answers (2)

Pratap A.K
Pratap A.K

Reputation: 4517

one way to achieve this is to write your business logic in a separate class and invoking that method in your service class.Take out that getProductCategories() method into other class and create instance of that class and call the method.So when you add new method in business class,no need to change wsdl or anything.But don't change the method signature and parameters.

Upvotes: 0

Rama Krishna Sanjeeva
Rama Krishna Sanjeeva

Reputation: 427

Web service is typically used for inter process communication and hence requires a strong contract for operating the service. The WSDL provides a means of such a contract. Hence, you will need updated WSDL every time there's a change in the contract.

However, there's still an option where WSDL is not required for service invocation. It can be achieved using dynamic invocation (https://access.redhat.com/site/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Development_Guide/Develop_a_JAX-WS_Client_Application.html). There are pros and cons. Depending on your use case, this may be a solution.

Upvotes: 1

Related Questions