I'm developing a web service with several methods taking as input identical complex data types. The data types have JAXB annotations and setters and getters, and the web service class has JAX-WS annotations.
Template of my service.java file:
@WebService(serviceName = "ServiceWS")
public class SericeWS {
private static ServiceIF serviceImpl;
static {
serviceImpl = new ServiceImpl();
}
public Result Method1(Credentials credentials) {
@WebParam(name = "credentials") Credentials credentials) {
return serviceImpl.Method1(credentials);
}
public Result Method2(Credentials credentials) {
@WebParam(name = "credentials") Credentials credentials) {
return serviceImpl.Method2(credentials);
}
}
EDIT: My Credentials.java file:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"password"
})
@XmlRootElement(name = "Credentials")
public class Credentials implements MyBean {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String password;
/**
* Gets the value of the name property.
*
* @return The name property of the credentials
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value The name property of the credentials
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the password property.
*
* @return The password property of the credentials
*
*/
public String getPassword() {
return password;
}
/**
* Sets the value of the password property.
*
* @param value The password property of the credentials
*
*/
public void setPassword(String password) {
this.password = password;
}
}
The service is deployed in Tomcat and the wsdl is auto-generated. When generating the client stubs with wsimport I get duplicate generation of the Credentials type (Credentials, Method1.Credentials and Method2.Credentials), i.e. a different (inner) class for each method.
It seems that the problem arrises when the wsdl and schema are generated :
<xs:schema xmlns:tns="http://service.my.package.com/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
targetNamespace="http://service.my.package.com/">
<xs:element name="Credentials">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
....
<xs:complexType name="getLockBoxKeys">
<xs:sequence>
<xs:element name="credentials" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
.....
How can I make all this work such that I have only one definition of Credentials? I am quite new to web services, JAX-WS and JAXB so I'm not sure I have the annotations right.
Any help would be greatly appreciated.