WebServices and Enums
Hi!
I'm trying to write a little web service using NetBeans 5.5.1 and Sun Application Server 9 on Mac OS X.
I have problems with objects containing enum attributes. These objects can't be used as a return value of a web method :(
Is there any solution to this? What am I doing wrong or is it just impossible to transfer enums?
Thank You!
# 1
Hello,
I am not sure, it might be possible to return an enum value, but i don't think so. I think it's not a good idea because i don't know how this should be processed by other toolkits/programming languages.
I would return the ordinal value:
@WebService()
public class EnumWebService {
public enum TestEnum {Red,Blue}
@WebMethod
public int operation() {
// do something
TestEnum t = TestEnum.Blue;
// do something else...
return t.ordinal();
}
Calling the web method returns a response value which can be easily converted to the corresponding enum value again:
TestEnum t2 = TestEnum.values()[responseValue];
Alex
# 2
enum as return type should work fine. Just tried a small example.
@WebService(serviceName="EnumService", portName="EnumPort",
targetNamespace="...")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public static class EnumEndpoint {
public enum MyEnum { Red, Blue };
public MyEnum get(int i) {
return i%2 == 0 ? MyEnum.Blue : MyEnum.Red;
}
}
jitua at 2007-7-12 20:17:53 >
