使用 MS/.NET/.asmx webservice 时如何在 Java/JAXB/CXF 端生成业务 POJO?
我们有几个基于 MS 的 Web 服务,在 Intranet 中显示为 .asmx?WSDL 链接。当使用最新的 Visual Studio 使用此 Web 服务时,没有问题。所有业务对象都有意义。我怀疑 Microsoft 在使用 ServiceReference 时使用了一些秘密握手,并且依赖于一些关于类型为
但是我们部门需要使用 Java 的所有内容。我选择的框架是 CXF (v.2.4.2),它与 Eclipse、SOAP-UI、Tomcat 配合良好。并且存在互操作性问题。首先,每个 wsdl 都必须手动修改。所有
。此后CXF即可完成生成客户端Java。但 Java 对象不是业务类型的 POJO。它们是某种 DOM 元素,就像
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <any/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"any"
})
public static class GetDepartmentsResult {
@XmlAnyElement(lax = true)
protected Object any;
/**
* Gets the value of the any property.
*
* @return
* possible object is
* {@link Object }
*
*/
public Object getAny() {
return any;
}
/**
* Sets the value of the any property.
*
* @param value
* allowed object is
* {@link Object }
*
*/
public void setAny(Object value) {
this.any = value;
}
}
在运行时测试代码时,一切正常。但每个对象都必须被视为 DOM 元素。我确信我在删除
或使用 wsld2java 时在某处犯了错误,因此它丢失了语义。但是我应该在 CXF 中做什么,才能使 Java 类看起来像 CSharp 类一样干净?
谢谢。
编辑:在 http://msdn.microsoft.com/en-us 得到一些线索/magazine/cc188755.aspx ,我希望当有人搜索相同答案时此链接将有效。其他查找文章的方式是:
MSDN 杂志 >问题>> 2003年四月> XML 文件:Web 服务和数据集
We have couple of MS based web-services, visible as .asmx?WSDL links in intranet. There is no problem when this webservices are consumed with latest Visual Studio. All business objects make sense. I suspect that Microsoft uses some secret handshake when ServiceReference is consumed and relies on some proprietary knowledge about what actual CSharp type is behind element typed as <s:schema>
But our department needs to use everything Java. My framework of choice is CXF (v.2.4.2) and it works well with Eclipse, SOAP-UI, Tomcat. And there are problems with interoperability. First, every wsdl have to be amended by hand. All <s:schema> <s:any> are replaced with single <s:any>
. After this CXF can finish generating client side Java. But the Java objects are not the business kind of POJOs. They are some kind of DOM Elements, like
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <any/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"any"
})
public static class GetDepartmentsResult {
@XmlAnyElement(lax = true)
protected Object any;
/**
* Gets the value of the any property.
*
* @return
* possible object is
* {@link Object }
*
*/
public Object getAny() {
return any;
}
/**
* Sets the value of the any property.
*
* @param value
* allowed object is
* {@link Object }
*
*/
public void setAny(Object value) {
this.any = value;
}
}
When the code is tested in runtime, everything works OK. But every object must be treated as DOM element. I am sure that I made a mistake somewhere by removing <s:schema>
or when used wsld2java, so it lost semantics. But what should I do exactly in CXF, to make Java classes to look as clean as CSharp ones ?
Thank you.
Edit: got some clues at http://msdn.microsoft.com/en-us/magazine/cc188755.aspx , I hope this link will be valid at later time, when someone search for the same answer. Other way to find article is:
MSDN Magazine > Issues > 2003 > April > The XML Files: Web Services and DataSets
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答:不可能。
经过详尽的研究,很明显,当服务端没有 Business CSharp 对象时,Business POJO 是不可能在客户端重建的。就这么简单。
在我的特殊情况下:
将来最好的场景是:
Answer: impossible.
After exaustive research it is obvious that Business POJOs are impossible to reconstruct on client, when service side has no Business CSharp objects. That simple.
In my particular situation:
In future, the best scenario is: