c# - 从 C# WS 客户端发送的枚举参数被 Java WS 接收为 null

标签 c# java web-services jboss enums

我有以下场景:我实现了一个在 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

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

最佳答案

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

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

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

关于c# - 从 C# WS 客户端发送的枚举参数被 Java WS 接收为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20290025/

相关文章:

c# - 数学舍入问题总计 > 100%

java - 为什么二进制表示为字符串?

java - 运行时异常 : Application "" could not be found in the registry.

android - 在android中调用rest webservice时超时异常

web-services - 如何通过指定 URL 访问 JAX-RS Web 服务目录中的文件?

c# - 如何获取嵌套括号之间的文本?

c# - Thread.Sleep() 窃取调试器焦点

c# - System.Text.Json:使用自动转换反序列化 JSON

java - 列表(ArrayList)比较

java - 无法获取Web服务的输出