-1

我们正在使用 CXF 网络服务。

设想:

一个服务电话正在恢复List<NoteDTO>。数据在那里,NoteDTO但在调用返回 List 的 Web 服务方法后,我们在NoteDTO类中看到空值。

日志中也没有任何类型的异常。

我的理解是 Web 服务中存在转换问题。

public class NoteDTO {


    /** The text of the note. */
    private String text;

    /** The date the note was created. */
    private Date created;

    /** The user who created the note. */
    private UserDTO createdBy;

    /** The date the note was last modified. */
    private Date modified;

    /** The last user to modify the note. */
    private UserDTO modifiedBy;


    private String wfStep;  

    public void setWfStep(String wfStep) {
        this.wfStep = wfStep;
    }

    /**
     * Default constructor for JAXB.
     */
    public NoteDTO() {
    }

    /**
     * Constructor taking basic values.
     * @param text The text of the note.
     * @param created The date created.
     * @param createdBy The user who create the note.
     */
    public NoteDTO(String text, Date created, UserDTO createdBy) {
        this.text = text;
        this.created = created;
        this.createdBy = createdBy;     
    }

    /**
     * Getter for the text of the note.
     * @return The text of the note.
     */
    public String getText() {
        return text;
    }

    /**
     * Setter for the text of the note.
     * @param text The text of the note.
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * Getter for the created date.
     * @return The created date.
     */
    public Date getCreated() {
        return created;
    }

    /**
     * Setter for the created date.
     * @param created The create date.
     */
    public void setCreated(Date created) {
        this.created = created;
    }

    /**
     * Getter for the modified date.
     * @return The modified date.
     */
    public Date getModified() {
        return modified;
    }

    /**
     * Setter for the modified date.
     * @param modified The modified date.
     */
    public void setModified(Date modified) {
        this.modified = modified;
    }

    /**
     * Getter for the created by user.
     * @return The created by user.
     */
    public UserDTO getCreatedBy() {
        return createdBy;
    }

    /**
     * Setter for the created by user.
     * @param createdBy The created by user.
     */
    public void setCreatedBy(UserDTO createdBy) {
        this.createdBy = createdBy;
    }

    /**
     * Getter for the modified by user.
     * @return The modified by user.
     */
    public UserDTO getModifiedBy() {
        return modifiedBy;
    }

    /**
     * Setter for the modified by user.
     * @param modifiedBy The modified by user.
     */
    public void setModifiedBy(UserDTO modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    /**
     * Getter for the workflow step.
     * @return The workflow step.
     */
    public String getWfstep() {
        return this.wfStep;
    }

我有一个网络服务课程

@WebService
public interface NotesService {

    /**
     * Get server notes for a specific workflow instance
     * @param workflowInstanceEntitityId Workflow Instance Entity ID
     * @return A list of notes.
     */
    List<NoteDTO> getNotesForWorkflowInstance(String bundleName, String workflowInstanceName);
}

数据在 NoteDTO 的另一边,但在调用后如下所示

notes = notesService.getNotesForWorkflowInstance(bundleName, workflowInstanceName);

我将 wfStep 属性值设为 null

有什么想法吗?

提前谢谢。

4

2 回答 2

0

可能@WebMethod注释会有所帮助吗?

于 2012-11-16T08:54:29.057 回答
0

您的类上没有适当的注释,所以我假设您使用的是 Java-First 方法。

我绝对确定您NoteDTO不是您的类型的XSD模式。WSDL如果您WSDL使用 java 代码生成,CXF您需要做的是在 Web 服务的对象上添加适当的注释。所以你的NoteDTO班级应该是这样的:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "NoteDTO", propOrder = {
    "text",
    "created",
    "createdBy",
    "modified",
    "modifiedBy",
    "wfStep"
})
public class NoteDTO {

    @XmlElement(name = "text")
    private String text;

    @XmlElement(name = "created")
    private Date created;

    @XmlElement(name = "createdBy")
    private UserDTO createdBy;

    @XmlElement(name = "modified")
    private Date modified;

    @XmlElement(name = "modifiedBy")
    private UserDTO modifiedBy;

    @XmlElement(name = "wfStep")
    private String wfStep;  

}

UserDTO您的 Web 服务调用中使用的任何其他对象相同。然后你的界面应该是这样的:

@WebService(targetNamespace = "http://your.target.namespace/", name = "NotesService")
@XmlSeeAlso({ObjectFactory.class})
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface NotesService {

    @WebResult(name = "getNotesForWorkflowInstanceResponse", targetNamespace = "http://your.target.namespace/")
    @WebMethod(operationName = "getNotesForWorkflowInstance", action = "http://your.target.namespace/getNotesForWorkflowInstance")
    public List<NoteDTO> getNotesForWorkflowInstance(
        @WebParam(name = "bundleName", targetNamespace = "http://your.target.namespace/") String bundleName,
        @WebParam(name = "workflowInstanceName", targetNamespace = "http://your.target.namespace/") String workflowInstanceName        
    );

}

未经测试,只是手动添加了所有内容。阅读有关 Java-First 方法的更多信息,您会发现自己做错了什么。这只是一个开始的提示。

于 2012-11-16T16:24:42.243 回答