我有以下场景:我实现了在JBoss 5.1上运行的Java WS(使用Seam 2.2.0.GA):
@Name("service")
@WebService(name = "Service", serviceName = "Service", targetNamespace = "http://app.service")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@Stateless
public class Service implements ServiceContract {
@Override
@WebMethod(operationName = "serviceOperation")
public OperationResponse serviceOperation(@WebParam(name = "queryType") QueryType queryType) {
this.log.info(queryType);
// Validate queryType is not null:
if (queryType == null) {
return new OperationResponse("queryType is null");
}
// ... elided
return new OperationResponse("Query OK");
}
}
@XmlType
public enum QueryType {
LOCAL,
REMOTE;
}
@XmlType(name = "operationResponse", propOrder = {"message"})
public class OperationResponse {
private String message;
public OperationResponse () {
}
// getters and setters
}
Java客户端很好地使用它:
public class ServiceClient {
public void consume() {
OperationResponse response = svc.serviceOperation(QueryType.LOCAL);
this.log.info("rcop = #0", response.getMessage());
}
}
服务打印:
INFO [Service] LOCAL
客户打印:
INFO [ServiceClient] Query OK
然而,如果从C#客户端(使用VS 2008生成)使用,则Java WS将queryType作为null
INFO [Service]
即使设置参数:
Service svc = new Service();
serviceOperation svcParams = new serviceOperation();
svcParams.queryType = queryType.LOCAL;
operationResponse response = svc.serviceOperation(svcParams);
Console.WriteLine(response.@return.message);
客户打印:
queryType is null
服务获取null而不是C#客户端设置的值的原因是什么?我已经在网上搜索过,发现与此问题无关。我错过了Java端枚举的任何注释吗?或者是VS生成的客户端有问题吗?非常感谢你的注意。
答案 0 :(得分:1)
我想出了一个我不喜欢的解决方案,但它确实有效。我没有使用枚举参数,而是将方法的签名更改为
public OperationResponse serviceOperation(@WebParam(name = "queryType") String queryType)
其中queryType必须是“LOCAL”或“REMOTE”之一,然后我使用Enum#valueOf(String)获取枚举实例。我真的需要枚举因为后来我在枚举类中添加了一个抽象方法,每个实例都必须实现一个特定的行为。