创建具有复杂类型的Web服务 [英] Creating a web service with complex types

查看:92
本文介绍了创建具有复杂类型的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web服务的新手,我使用一种公开的方法在eclipse中创建了一个基本项目。我能够部署我的web服务,它工作正常。代码如下。

I'm new to web services and I created a basic project in eclipse with one exposed method. I was able to deploy my webservice and it works fine. The code is below.

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(targetNamespace="http://test.com", name="testService")
public class WebService {
    @WebMethod(operationName="start")
    public String start(@WebParam(name="inputParameter") String inputParameter) {
        return startMethod(inputParameter);
    }
}

我的问题是如何设置此方法处理复杂的类型。我想收到一些参数,但我不想只是接收它们作为一堆字符串。我在考虑使用某种包装器对象,其中包含我的方法所需的所有参数。关于如何做到这一点的任何建议?我是否需要额外的注释来创建WSDL?谢谢!

My question is how do I set up this method to deal with complex types. I want to receive a number of parameters, but I don't want to just receive them as a bunch of strings. I was thinking of having some sort of wrapper object that contained all the parameters I need for my method. Any advice on how to do this? Do I need additional annotations to create the WSDL? Thanks!

推荐答案

JAX-WS基于JAXB,因此您只能将JAXB支持的类型作为Web方法参数传递。因此,任何正确注释的用户定义类(如下所述)都可以用作任何WebMethod的参数或返回类型

JAX-WS is based on JAXB so you can pass only JAXB supported types as a web method parameters. So any user defined class properly annotated such as mentioned below can be used as parameter or return type of any WebMethod

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Person")
public class Person {    
    @XmlElement(name = "firstName")
    protected String firstName;    
    @XmlElement(name = "lastName")
    protected String lastName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String value) {
        this.firstName = value;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String value) {
        this.lastName = value;
    }
}

这篇关于创建具有复杂类型的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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