繁体   English   中英

从C#WS客户端发送的Enum参数被Java WS接收为null

[英]Enum parameter sent from C# WS client is received as null by Java WS

我有以下情形:我实现了在JBoss 5.1(带有Seam 2.2.0.GA)上运行的Java WS:

@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

服务获取空值而不是C#客户端设置的值的原因是什么? 我已经在网上搜索了,没有发现与此问题相关的信息。 我是否在Java端缺少枚举的任何注释? 还是VS生成的客户端有问题? 多谢您四次注意。

我想出了一个我不太喜欢的解决方案,但它确实有效。 我没有使用enum参数,而是将方法的签名更改为

public OperationResponse serviceOperation(@WebParam(name = "queryType") String queryType)

其中queryType必须为“ LOCAL”或“ REMOTE”之一,然后使用Enum#valueOf(String)获得枚举实例。 我确实需要枚举,因为后来我向枚举类添加了抽象方法,并且每个实例都必须实现特定的行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM