使用 WSDL,我们可以在作为 Web 服务方法参数的类中生成其他公共方法吗?
抱歉,如果问题没有明确说明我需要什么......请提前阅读要求。
我正在使用 JAX-WS 2.2.3。
我已经实现了一个 Web 服务类,它有一个方法 int addRecord(Record)。 Record 类包含一个实例成员作为 Attribute 类的集合。现在,Record 类包含一个公共 void addAttribute(Attribute objAttribute) 方法。
我已经使用 wsgen ant 任务为此类生成了 WSDL。
当我对此 WSDL 以及其他类执行 wsimport 时,我仅获得一个包含实例成员的 set/get 方法的 Record 类,而不是包含 void addAttribute(Attribute objAttribute) 方法。
有没有办法在 Record 类上也获取此方法?
SOURCE CODE:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(名称 = "记录")
公共类 Record 实现 Serialized
{
/**
*
*/
私有静态最终长serialVersionUID = 1L;
@XmlElement(name = "AttributeList")
List<Attribute> objAttributeList;
public void addAttribute(Attribute objAttribute)
{
objAttributeList.add(objAttribute);
}
@XmlAccessorType
(XmlAccessType.FIELD)
@XmlType(名称 = "属性")
公共类属性实现可序列化
{
@XmlElement(名称 = "Id")
整数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
}
}
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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不 - 不适用于网络服务。
Web 服务的系统比喻是消息传递。有一个客户端和一个服务器,它们通过预先安排的通信协议或合约交换消息。消息和交换在 WSDL 中描述。
您想象的是一个分布式对象系统,您在其中传输对象而不是消息。这通常不是 Web 服务工具(适用于任何平台)支持的模型。
考虑更改您的架构以使用 DTO - 数据传输对象 - 来进行交换。然后在不同的业务级对象中实现逻辑,这些对象可能使用 适配器模式 来获取其状态来自 DTO。如果您愿意,业务对象可以是共享数据类型;换句话说,定义类型并从客户端内部和服务器内部引用的单个 JAR。
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.