如何使用Web服务在组中将自定义对象公开为参数?
例如,我有一个名为OrderWS.java
的类,在该类中我有OrderLineWS.java
作为参数。现在,当我在客户端将此OrderWS.java
公开给Web服务时。它不包括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;
}
}
OrderLineWS.java
package com.dev.backend.order;
import java.io.Serializable;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.dev.backend.product.ProductWS;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class OrderLineWS implements Serializable{
private Integer quantity;
private BigDecimal unitPrice;
private BigDecimal totalPrice;
private String productCode;
private String orderCode;
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
public BigDecimal getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getOrderCode() {
return orderCode;
}
public void setOrderCode(String orderCode) {
this.orderCode = orderCode;
}
}
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>
* <complexType name="orderWS">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="customerCode" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="orderNumber" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="totalPrice" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </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;
}
}