Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JAX-WS将bean方法传递给客户端_Java_Web Services_Netbeans_Jax Ws - Fatal编程技术网

Java JAX-WS将bean方法传递给客户端

Java JAX-WS将bean方法传递给客户端,java,web-services,netbeans,jax-ws,Java,Web Services,Netbeans,Jax Ws,我用Netbeans做了一个web服务。我试图理解为什么bean的方法不能由客户机生成 package OnlineAuction.client; import java.math.BigDecimal; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; /**

我用Netbeans做了一个web服务。我试图理解为什么bean的方法不能由客户机生成

package OnlineAuction.client;

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 auction complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="auction">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="added" type="{http://OnlineAuction/}timestamp" minOccurs="0"/>
 *         &lt;element name="expire" type="{http://OnlineAuction/}timestamp" minOccurs="0"/>
 *         &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}long" minOccurs="0"/>
 *         &lt;element name="product" type="{http://OnlineAuction/}product" minOccurs="0"/>
 *         &lt;element name="reserve" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
 *         &lt;element name="startingBid" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "auction", propOrder = {
    "added",
    "expire",
    "id",
    "product",
    "reserve",
    "startingBid"
})
public class Auction {

    protected Timestamp added;
    protected Timestamp expire;
    protected Long id;
    protected Product product;
    protected BigDecimal reserve;
    protected BigDecimal startingBid;

    /**
     * Gets the value of the added property.
     * 
     * @return
     *     possible object is
     *     {@link Timestamp }
     *     
     */
    public Timestamp getAdded() {
        return added;
    }

    /**
     * Sets the value of the added property.
     * 
     * @param value
     *     allowed object is
     *     {@link Timestamp }
     *     
     */
    public void setAdded(Timestamp value) {
        this.added = value;
    }

    /**
     * Gets the value of the expire property.
     * 
     * @return
     *     possible object is
     *     {@link Timestamp }
     *     
     */
    public Timestamp getExpire() {
        return expire;
    }

    /**
     * Sets the value of the expire property.
     * 
     * @param value
     *     allowed object is
     *     {@link Timestamp }
     *     
     */
    public void setExpire(Timestamp value) {
        this.expire = value;
    }

    /**
     * Gets the value of the id property.
     * 
     * @return
     *     possible object is
     *     {@link Long }
     *     
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the value of the id property.
     * 
     * @param value
     *     allowed object is
     *     {@link Long }
     *     
     */
    public void setId(Long value) {
        this.id = value;
    }

    /**
     * Gets the value of the product property.
     * 
     * @return
     *     possible object is
     *     {@link Product }
     *     
     */
    public Product getProduct() {
        return product;
    }

    /**
     * Sets the value of the product property.
     * 
     * @param value
     *     allowed object is
     *     {@link Product }
     *     
     */
    public void setProduct(Product value) {
        this.product = value;
    }

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

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

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

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

}
这是豆子

package OnlineAuction;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;


public class Auction implements Serializable {
    private static final long serialVersionUID = 1L;
    private Long id;
    private Product product;
    private Timestamp added;
    private Timestamp expire;
    private BigDecimal startingBid;
    private BigDecimal reserve;

    /**
     *
     * @return
     */
    public Long getId() {
        return id;
    }

    /**
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Auction)) {
            return false;
        }
        Auction other = (Auction) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "OnlineAuction.Auction[ id=" + id + " ]";
    }

    /**
     *
     * @return
     */
    public Product getProduct() {
        return product;
    }

    /**
     *
     * @param product
     */
    public void setProduct(Product product) {
        this.product = product;
    }

    /**
     *
     * @return
     */
    public Timestamp getAdded() {
        return added;
    }

    /**
     *
     * @param added
     */
    public void setAdded(Timestamp added) {
        this.added = added;
    }

    /**
     *
     */
    public void setAddedNow() {
        this.added = getTimestampNow();
    }

    private Timestamp getTimestampNow() {
        java.util.Date date = new java.util.Date();
        return new Timestamp(date.getTime());
    }

    /**
     *
     * @return
     */
    public Timestamp getExpire() {
        return expire;
    }

    /**
     *
     * @param expire
     */
    public void setExpire(Timestamp expire) {
        this.expire = expire;
    }

    /**
     * Sets the expiry time of the auction by adding the hours to the added date.
     * If the added date is not set this function will set the added date to current time.
     * @param hours to be added to the added time of the auction
     */
    public void setExpire(int hours) {
        // Set added time if null
        if (this.added == null) {
            this.setAddedNow();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(this.added);
        cal.add(Calendar.HOUR, hours);
        Date date = cal.getTime();
        this.expire = new Timestamp(date.getTime());
    }

    /**
     *
     * @return
     */
    public BigDecimal getStartingBid() {
        return startingBid;
    }

    /**
     *
     * @param startingBid
     */
    public void setStartingBid(BigDecimal startingBid) {
        this.startingBid = startingBid;
    }

    /**
     *
     * @return
     */
    public BigDecimal getReserve() {
        return reserve;
    }

    /**
     *
     * @param reserve
     */
    public void setReserve(BigDecimal reserve) {
        this.reserve = reserve;
    }


    public boolean isAuctionExpired() {
        boolean expired;
        if (this.getTimestampNow().compareTo(this.expire) > 0) {
            // now is greater than expire date
            expired = true;
        } else {
            // now is less than expire date
            expired = false;
        }

        return expired;
    }

}
下面是JAX-WS为客户机生成的源代码

package OnlineAuction.client;

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 auction complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="auction">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="added" type="{http://OnlineAuction/}timestamp" minOccurs="0"/>
 *         &lt;element name="expire" type="{http://OnlineAuction/}timestamp" minOccurs="0"/>
 *         &lt;element name="id" type="{http://www.w3.org/2001/XMLSchema}long" minOccurs="0"/>
 *         &lt;element name="product" type="{http://OnlineAuction/}product" minOccurs="0"/>
 *         &lt;element name="reserve" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
 *         &lt;element name="startingBid" type="{http://www.w3.org/2001/XMLSchema}decimal" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "auction", propOrder = {
    "added",
    "expire",
    "id",
    "product",
    "reserve",
    "startingBid"
})
public class Auction {

    protected Timestamp added;
    protected Timestamp expire;
    protected Long id;
    protected Product product;
    protected BigDecimal reserve;
    protected BigDecimal startingBid;

    /**
     * Gets the value of the added property.
     * 
     * @return
     *     possible object is
     *     {@link Timestamp }
     *     
     */
    public Timestamp getAdded() {
        return added;
    }

    /**
     * Sets the value of the added property.
     * 
     * @param value
     *     allowed object is
     *     {@link Timestamp }
     *     
     */
    public void setAdded(Timestamp value) {
        this.added = value;
    }

    /**
     * Gets the value of the expire property.
     * 
     * @return
     *     possible object is
     *     {@link Timestamp }
     *     
     */
    public Timestamp getExpire() {
        return expire;
    }

    /**
     * Sets the value of the expire property.
     * 
     * @param value
     *     allowed object is
     *     {@link Timestamp }
     *     
     */
    public void setExpire(Timestamp value) {
        this.expire = value;
    }

    /**
     * Gets the value of the id property.
     * 
     * @return
     *     possible object is
     *     {@link Long }
     *     
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the value of the id property.
     * 
     * @param value
     *     allowed object is
     *     {@link Long }
     *     
     */
    public void setId(Long value) {
        this.id = value;
    }

    /**
     * Gets the value of the product property.
     * 
     * @return
     *     possible object is
     *     {@link Product }
     *     
     */
    public Product getProduct() {
        return product;
    }

    /**
     * Sets the value of the product property.
     * 
     * @param value
     *     allowed object is
     *     {@link Product }
     *     
     */
    public void setProduct(Product value) {
        this.product = value;
    }

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

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

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

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

}
package OnlineAuction.client;
导入java.math.BigDecimal;
导入javax.xml.bind.annotation.XmlAccessType;
导入javax.xml.bind.annotation.XmlAccessorType;
导入javax.xml.bind.annotation.XmlType;
/**
*拍卖复杂类型的Java类。
* 
*以下架构片段指定此类中包含的预期内容。
* 
* 
*complexType name=“拍卖”>
*complexContent>
*限制基数=”{http://www.w3.org/2001/XMLSchema}任何类型“>
*序列>
*元素名称=“已添加”类型=”{http://OnlineAuction/}时间戳“minOccurs=“0”/>
*元素名称=“过期”类型=“{http://OnlineAuction/}时间戳“minOccurs=“0”/>
*元素名称=“id”类型=”{http://www.w3.org/2001/XMLSchema}长“minOccurs=”0“/>
*元素名称=“产品”类型=”{http://OnlineAuction/}产品“minOccurs=”0“/>
*元素名称=“保留”类型=”{http://www.w3.org/2001/XMLSchema}十进制“minOccurs=“0”/>
*元素名称=“startingBid”类型=”{http://www.w3.org/2001/XMLSchema}十进制“minOccurs=“0”/>
*/顺序>
*/限制>
*/complexContent>
*/complexType>
* 
* 
* 
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name=“拍卖”,比例器={
“添加”,
“到期”,
“身份证”,
“产品”,
“储备”,
“开始投标”
})
公开拍卖{
添加受保护的时间戳;
受保护的时间戳过期;
保护长id;
受保护产品;
保护区;
受保护的BigDecimal startingBid;
/**
*获取所添加属性的值。
* 
*@返回
*可能的对象是
*{@link Timestamp}
*     
*/
公共时间戳getAdded(){
增加了退货;
}
/**
*设置所添加属性的值。
* 
*@param值
*允许的对象是
*{@link Timestamp}
*     
*/
已添加公共void setAdded(时间戳值){
这是增加值;
}
/**
*获取expire属性的值。
* 
*@返回
*可能的对象是
*{@link Timestamp}
*     
*/
公共时间戳getExpire(){
返回到期;
}
/**
*设置expire属性的值。
* 
*@param值
*允许的对象是
*{@link Timestamp}
*     
*/
公共void setExpire(时间戳值){
this.expire=值;
}
/**
*获取id属性的值。
* 
*@返回
*可能的对象是
*{@link Long}
*     
*/
公共长getId(){
返回id;
}
/**
*设置id属性的值。
* 
*@param值
*允许的对象是
*{@link Long}
*     
*/
公共void setId(长值){
this.id=值;
}
/**
*获取产品属性的值。
* 
*@返回
*可能的对象是
*{@link-Product}
*     
*/
公共产品{
退货产品;
}
/**
*设置产品属性的值。
* 
*@param值
*允许的对象是
*{@link-Product}
*     
*/
公共产品(产品价值){
这个产品=价值;
}
/**
*获取保留属性的值。
* 
*@返回
*可能的对象是
*{@link BigDecimal}
*     
*/
public bigReserve(){
回报准备金;
}
/**
*设置保留属性的值。
* 
*@param值
*允许的对象是
*{@link BigDecimal}
*     
*/
公共无效设置保留(BigDecimal值){
这个。储备=价值;
}
/**
*获取startingBid属性的值。
* 
*@返回
*可能的对象是
*{@link BigDecimal}
*     
*/
公共BigDecimal getStartingBid(){
返标;
}
/**
*设置startingBid属性的值。
* 
*@param值
*允许的对象是
*{@link BigDecimal}
*     
*/
公共无效设置开始出价(大十进制值){
this.startingBid=价值;
}
}

那么为什么我的bean方法
isAuctionExpired()
不在生成的源代码中呢?我可以通过添加一个
auctionExpired
属性来欺骗这一点,但我不想这样做。

JAX-WS客户端是使用Web服务的WSDL生成的。WSDL只有将用于服务器和客户端之间通信的类型的属性。因此,您将永远无法在服务器和客户端之间传递方法实现。下面注释中的信息是客户端类生成器在生成客户端时拥有的所有信息

此信息取自WSDL。
您必须了解XML用于服务器和客户端之间的通信。因此,Web服务中的代码不能传递给客户端,反之亦然。Web服务和客户端可以用两种不同的技术编写。因此,如果客户机是用任何其他语言实现的,那么将java代码传递给客户机没有任何意义。
简而言之,您可以在客户端和服务器之间传递信息,但不能传递行为。

非常感谢您,我怀疑这一点。