Thursday, September 11, 2008

Axis2 java2wsdl - Never Use An Interface

Well this is not an issue with Axis2 but rather the way Java treats an Interface. There has been numerous occasions when users have been bugged by this (Parameter names appearing as param0, param1 in the WSDL instead of the actual parameter names). This could happen because of two reasons,
  1. Your service class was compiled without the debug option been turned on. Please refer How to make WSDL display actual parameter names? in order to see how this issue can be avoided.
  2. You used an Interface as the service class name when using java2wsdl. For this I'm sorry - there is no solution. Even if you had turned on the debug option when compiling the interface, java would not push down the parameter names into the compiled code (After all, its an interface and it just defines the contract and the actual class thats implementing this interface may have called those parameters something else)
So the bottom line is this. Always avoid using an Interface as the service class when using java2wsdl and when using a class, please make sure that its compiled with the debug option turned on.

7 comments:

SteveL said...

Surely the root issue is never try and derive WSDL from java source?

Keith Chapman said...

Well not really. Never use an interface to do that and if your using a class, make sure thats its compiled with debug options turned on.

There may be occasions where you want to do contract-first web services. Now writing a WSDL from scratch may be too hard for you. In such a scenario using a tool such as java2wsdl can help. You can later tinker the generated WSDL to suit your needs.

Unknown said...

Isn't this what the @WebParam annotation is for? I don't know a lot about Axis2 so it may ignore that annotation.

Keith Chapman said...

I believe @WebParam could be used when deploying a JaxWS Service, but I don't think its used when generating a WSDL.

Zviki Cohen said...

The problem with generating a WSDL from the class is that it may include methods you do not wish to expose. Methods which cannot be private (e.g. in the case when injecting dependencies with Spring).

Is there a way to select which methods should be exposed?

Unknown said...

As per the specifications we can avoid exposing a public method in the service class using the @WebMethod(exclude = "true").

That seems to be fine, but I am not able to use the @WebParam(header = true) using axis2 and annotations. I am using axis2 war on tomcat6. But all the staff are coming in the soap body. Has anybody tried the header = true things in WebParam and WeResult ???

Windu Purnomo said...

Sorry, I am new bie in web service, I need your help.
I create a service that return List of Person (Lis‹Person›). Person is Java Bean. When I test this service, it is can not run. To compare I create the other simple service that return String. I test in browser, it is running well.
Is web service can not handle non primitive data type? is there other way to solve this problem?