Java 如何在web服务中公开自定义对象

Java 如何在web服务中公开自定义对象,java,web-services,jax-ws,Java,Web Services,Jax Ws,如何在使用web服务的类中将自定义对象作为参数公开 例如,我有一个名为OrderWS.java的类,在该类中我有OrderLineWS.java作为参数。现在,当我向客户端的web服务公开这个OrderWS.java时。它没有将OrderLineWS作为参数包含在客户端的OrderWS类中。有人能帮我吗 OrderWS.java package com.dev.backend.order; import java.io.Serializable; import java.math.BigDec

如何在使用web服务的类中将自定义对象作为参数公开

例如,我有一个名为
OrderWS.java
的类,在该类中我有
OrderLineWS.java
作为参数。现在,当我向客户端的web服务公开这个
OrderWS.java
时。它没有将
OrderLineWS
作为参数包含在客户端的
OrderWS
类中。有人能帮我吗

OrderWS.java

package com.dev.backend.order;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.dev.backend.customer.CustomerWS;

public class OrderWS implements Serializable{

    private String orderNumber;
    private String customerCode ;
    private BigDecimal totalPrice;
    private List<OrderLineWS> orderLineWSs = new ArrayList<OrderLineWS>();

    public String getOrderNumber() {
        return orderNumber;
    }
    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }
    public String getCustomerCode() {
        return customerCode;
    }
    public void setCustomerCode(String customerCode) {
        this.customerCode = customerCode;
    }
    public BigDecimal getTotalPrice() {
        return totalPrice;
    }
    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }
    public List<OrderLineWS> getOrderLineWSs() {
        return orderLineWSs;
    }
    public void setOerLineWSs(List<OrderLineWS> orderLineWSs) {
        this.orderLineWSs = orderLineWSs;
    }

}
IWebService.java

package com.dev.backend.webservices;

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

import com.dev.backend.customer.CustomerWS;
import com.dev.backend.order.OrderWS;
import com.dev.backend.product.ProductWS;

@WebService
public interface IWebService {

    @WebMethod
    Integer saveOrder(OrderWS orderWS);
}
我使用这个命令在客户端生成了类

wsimport -Xnocompile . http://localhost:8080/WS/IWebService?wsdl
在客户端,OrderWS.java是这样生成的

package com.dev.backend.webservices;

import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for orderWS complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="orderWS">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="customerCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="orderNumber" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="totalPrice" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "orderWS", propOrder = {
    "customerCode",
    "orderNumber",
    "totalPrice"
})
public class OrderWS {

    protected String customerCode;
    protected String orderNumber;
    protected BigDecimal totalPrice;

    /**
     * Gets the value of the customerCode property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getCustomerCode() {
        return customerCode;
    }

    /**
     * Sets the value of the customerCode property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setCustomerCode(String value) {
        this.customerCode = value;
    }

    /**
     * Gets the value of the orderNumber property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getOrderNumber() {
        return orderNumber;
    }

    /**
     * Sets the value of the orderNumber property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setOrderNumber(String value) {
        this.orderNumber = value;
    }

    /**
     * Gets the value of the totalPrice property.
     * 
     * @return
     *     possible object is
     *     {@link BigDecimal }
     *     
     */
    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    /**
     * Sets the value of the totalPrice property.
     * 
     * @param value
     *     allowed object is
     *     {@link BigDecimal }
     *     
     */
    public void setTotalPrice(BigDecimal value) {
        this.totalPrice = value;
    }

}
package com.dev.backend.webservices;
导入java.math.BigDecimal;
导入javax.xml.bind.annotation.XmlAccessType;
导入javax.xml.bind.annotation.XmlAccessorType;
导入javax.xml.bind.annotation.XmlType;
/**
*用于orderWS复杂类型的Java类。
* 
*以下架构片段指定此类中包含的预期内容。
* 
* 
*complexType name=“orderWS”>
*complexContent>
*限制基数=”{http://www.w3.org/2001/XMLSchema}任何类型“>
*序列>
*元素名称=“customerCode”类型=”{http://www.w3.org/2001/XMLSchema}字符串“minOccurs=”0“/>
*元素名称=“订单号”类型=”{http://www.w3.org/2001/XMLSchema}字符串“minOccurs=”0“/>
*元素名称=“totalPrice”类型=”{http://www.w3.org/2001/XMLSchema}十进制“minOccurs=“0”/>
*/顺序>
*/限制>
*/complexContent>
*/complexType>
* 
* 
* 
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=“orderWS”,proporter={
“客户代码”,
“订单号”,
“总价格”
})
公共类OrderWS{
受保护的字符串自定义代码;
受保护的字符串顺序号;
保护价格;
/**
*获取customerCode属性的值。
* 
*@返回
*可能的对象是
*{@link String}
*     
*/
公共字符串getCustomerCode(){
返回客户代码;
}
/**
*设置customerCode属性的值。
* 
*@param值
*允许的对象是
*{@link String}
*     
*/
public void setCustomerCode(字符串值){
this.customerCode=值;
}
/**
*获取orderNumber属性的值。
* 
*@返回
*可能的对象是
*{@link String}
*     
*/
公共字符串getOrderNumber(){
退货订单号;
}
/**
*设置orderNumber属性的值。
* 
*@param值
*允许的对象是
*{@link String}
*     
*/
public void setOrderNumber(字符串值){
this.orderNumber=值;
}
/**
*获取totalPrice属性的值。
* 
*@返回
*可能的对象是
*{@link BigDecimal}
*     
*/
公共BigDecimal getTotalPrice(){
返回总价;
}
/**
*设置totalPrice属性的值。
* 
*@param值
*允许的对象是
*{@link BigDecimal}
*     
*/
公共无效setTotalPrice(BigDecimal值){
这个。总价格=价值;
}
}

您能提供示例类吗?@frankelydiaz添加了示例。请帮帮我。今天真的需要解决它。@CornelCreanga你能在这里帮我一下吗。
package com.dev.backend.webservices;

import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for orderWS complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="orderWS">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="customerCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="orderNumber" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         &lt;element name="totalPrice" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "orderWS", propOrder = {
    "customerCode",
    "orderNumber",
    "totalPrice"
})
public class OrderWS {

    protected String customerCode;
    protected String orderNumber;
    protected BigDecimal totalPrice;

    /**
     * Gets the value of the customerCode property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getCustomerCode() {
        return customerCode;
    }

    /**
     * Sets the value of the customerCode property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setCustomerCode(String value) {
        this.customerCode = value;
    }

    /**
     * Gets the value of the orderNumber property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getOrderNumber() {
        return orderNumber;
    }

    /**
     * Sets the value of the orderNumber property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setOrderNumber(String value) {
        this.orderNumber = value;
    }

    /**
     * Gets the value of the totalPrice property.
     * 
     * @return
     *     possible object is
     *     {@link BigDecimal }
     *     
     */
    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    /**
     * Sets the value of the totalPrice property.
     * 
     * @param value
     *     allowed object is
     *     {@link BigDecimal }
     *     
     */
    public void setTotalPrice(BigDecimal value) {
        this.totalPrice = value;
    }

}