如何使用HashMap作为Web服务中的参数 [英] How to use HashMap as a parameter in Web service

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

问题描述

我试图创建一个动态Web服务,其中我将期望一个Java哈希映射或数组列表的参数。

I am trying to make a dynamic Web Service in which i will be expecting a Java hash map or an Array list for the argument.

我使用以下类代码中的代码:

I am using the following code in Class Code:

package demo;

import java.util.ArrayList;

import javax.jws.WebService;

@WebService
public class HashMapTest {
    public HashMapTest() {
        super();
    }

    public int getResponse(ArrayList<String> hm) {
        return hm.size();
    }
}



我使用的是IDE:Oracle Jdeveloper 11g。当我使用向导时,输出WSDL如下:

I am using an IDE: Oracle Jdeveloper 11g. when i use the Wizard in the same, the output WSDL is as given below:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
     name="HashMapTestService"
     targetNamespace="http://demo/"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
     xmlns:tns="http://demo/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    >
    <wsdl:types>
    </wsdl:types>
    <wsdl:portType name="HashMapTest">
    </wsdl:portType>
    <wsdl:binding name="HashMapTestSoapHttp" type="tns:HashMapTest">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    </wsdl:binding>
    <wsdl:service name="HashMapTestService">
        <wsdl:port name="HashMapTestPort" binding="tns:HashMapTestSoapHttp">
            <soap:address location="http://localhost:7101/DemoServer-Demo-context-root/HashMapTestPort"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

很容易看出,WSDL已损坏,无法使用。

As easily seen, the WSDL is corrupt and cannot be used.

这只是Jdeveloper中的一个错误,还是我们不能在Web服务中使用Collections API作为参数?

Is it just a bug in Jdeveloper or can we simply not use Collections API in Web service as a parameter?

请帮助

推荐答案

这是由JAXB中的错误造成的。使用以下代码:

this is caused by bug in JAXB . Use the following Code:

public class DTOObject
{ 
        HashMap hm = new HashMap();

    public void setHm(HashMap hm) {
        this.hm = hm;
    }

    public HashMap getHm() {
        return hm;
    }

    public int size() {
        return hm.size();
    }
}

public class HashMapTest {
    public HashMapTest() {
        super();
    }

    public int getResponse(Wrapped hm) {

        System.out.println(hm);
        return hm.size();
    }


}

并正确地创建wsdl。

It will solve the issue and create the wsdl correctly.

这篇关于如何使用HashMap作为Web服务中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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