Search code examples
javaweb-serviceswsdljax-ws

Using WSDL, can we generate other public methods inside a class that is a parameter of a Web Service Method?


Sorry, if the question does not clarify exactly what i need....Please read ahead for the requirement.

I am using JAX-WS 2.2.3.

I have implemented a web service class which has a method int addRecord(Record). The Record class contains an instance member as collection of Attribute class. Now, the Record class contains a public void addAttribute(Attribute objAttribute) method.

I have generated the WSDL for this class using the wsgen ant task.

When i do a wsimport on this WSDL, alon gwith other classes, i only get a Record class that contains set/get methods for the instance member and not the void addAttribute(Attribute objAttribute) method.

Is there a way to get this method also on the Record class?


SOURCE CODE:

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "Record") public class Record implements Serializable { /** * */ private static final long serialVersionUID = 1L;

@XmlElement(name = "AttributeList")
List<Attribute> objAttributeList;


public void addAttribute(Attribute objAttribute)
{
    objAttributeList.add(objAttribute);
}

}

@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Attribute") public class Attribute implements Serializable { @XmlElement(name = "Id") int id;

@XmlElement(name = "Name")
String name;

@XmlElement(name = "Value")
Object value;

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public Object getValue() {
    return value;
}
public void setValue(Object value) {
    this.value = value;
}

}

@WebService class RecordService { @WebMethod public int addRecord(Record objRecord) { //code to process record object } }

Solution

  • No - not with web services.

    The system metaphor with web services is message passing. There is a client and a server and they exchange messages via a pre-arranged communication protocol or contract. The messages and the exchanges are described in WSDL.

    What you are imagining is a distributed object system, where you transmit objects and not messages. This is generally not the model that web services tools (for any platform) support.

    Consider changing your architecture to use DTOs - Data Transfer Objects - for the things that get exchanged. Then implement logic in different business-level objects that maybe use the Adapter pattern to slurp their state from the DTO. The business objects could be shared data types, if you like; in other words a single JAR that defines the type and gets referenced from within client and from within server.