如何使用 JBossWS 3.1.2 将 HashMap 作为 @WebParam [英] How to have a HashMap as @WebParam with JBossWS 3.1.2

查看:22
本文介绍了如何使用 JBossWS 3.1.2 将 HashMap 作为 @WebParam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JBossWS 3.1.2 开发 Web 服务,该服务将 HashMap 作为其参数之一.我正在使用此版本的 JBossWS,因为这是随我使用的 JBoss 版本一起分发的.我使用 wsprovide 生成 WSDL,使用 wsconsume 创建 WS 客户端存根.

I am trying to develop a web service with JBossWS 3.1.2 that has a HashMap as one of its arguments. I am using this version of JBossWS because that is what is distributed with the version of JBoss that I am using. I am using wsprovide to generate the WSDL and wsconsume to create WS client stubs.

我的 WebService 的简化版本是:

A simplified version of my WebService is:

@WebService(targetNamespace = "http://localhost/ping", serviceName = "Ping")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class Ping {
    @WebMethod
    @WebResult(name="result")
    public String ping(@WebParam(name="arguments") HashMap arguments) {
        return "pong";
    }
}

wsprovide 创建的 WSDL 包含:

The WSDL created by wsprovide contains:

<types>
    <xs:schema targetNamespace='http://localhost/ping' version='1.0' xmlns:tns='http://localhost/ping' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
        <xs:complexType name='hashMap'>
            <xs:complexContent>
                <xs:extension base='tns:abstractMap'>
                    <xs:sequence/>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>
        <xs:complexType abstract='true' name='abstractMap'>
            <xs:sequence/>
        </xs:complexType>
    </xs:schema>
</types>

生成的客户端代码包含一个空抽象类 AbstractMap.java 和一个空类 HashMap.

The generated client code contains an empty abstract class AbstractMap.java and an empty class HashMap.

我希望生成类似于以下内容的 WSDL:

I would have expected WSDL similar to the following to have been generated:

<complexType>
    <sequence>
        <element name="key" type="anyType" />
        <element name="value" type="anyType" />
    </sequence>
</complexType>

我也尝试用自定义类 (ParameterMap) 包装 HashMap,但得到了更多相同的结果.

I also tried wrapping HashMap with a custom class (ParameterMap) but just got more of the same.

是否有我没有看到的下一步?我是否遗漏了什么,或者这是对使用 JBossWS 开发 Web 服务的自下而上方法的限制?

Is there a next step that I'm not seeing? Am I missing something or is this a limitation to the bottom up approach to developing Web Services with JBossWS?

推荐答案

答案在另一篇文章 如何将数组作为值传入 PHP soapclient 请求?

我从没想过要为 JAX-WS 解决方案调查 PHP 问题...

I would have never thought to look into a PHP question for a JAX-WS solution...

HashMap 需要包装在另一个名为 HashMapWrapper.java(或其他)的 Java 类中.

The HashMap needs to be wrapped in another Java class called HashMapWrapper.java (or whatever).

public class HashMapWrapper {
    public HashMap<String, Object> parameters;
}

ping 方法调用需要修改为使用包装类而不是 HashMap:

The ping method call needs to be modified to use the wrapper class instead of HashMap:

public String ping(@WebParam(name="arguments") HashMapWrapper arguments) {

这会生成适当的 WSDL,进而生成有用的 Java 存根.

This generates appropriate WSDL which in turns generates useful Java stubs.

这篇关于如何使用 JBossWS 3.1.2 将 HashMap 作为 @WebParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆