我正在使用几种方法开发一个 Web 服务,将相同的复杂数据类型作为输入。数据类型具有 JAXB 注释以及 setter 和 getter,Web 服务类具有 JAX-WS 注释。
我的 service.java 文件的模板:
@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);
}
}
编辑:我的 Credentials.java 文件:
@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;
}
}
该服务部署在 Tomcat 中,并且 wsdl 是自动生成的。当使用 wsimport 生成客户端存根时,我会重复生成 Credentials 类型(Credentials、Method1.Credentials 和 Method2.Credentials),即每个方法都有一个不同的(内部)类。
似乎在生成 wsdl 和模式时出现了问题:
<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>
.....
我怎样才能使所有这些工作使我只有一个凭据定义?我对 Web 服务、JAX-WS 和 JAXB 很陌生,所以我不确定我的注释是否正确。
任何帮助将不胜感激。