我们有几个基于 MS 的 Web 服务,在 Intranet 中显示为 .asmx?WSDL 链接。使用最新的 Visual Studio 使用此 Web 服务时没有问题。所有业务对象都有意义。我怀疑微软在使用 ServiceReference 时使用了一些秘密握手,并且依赖于一些专有知识,即关于元素类型背后的实际 CSharp 类型是什么<s:schema>
但是我们部门需要使用 Java 的一切。我选择的框架是 CXF (v.2.4.2),它适用于 Eclipse、SOAP-UI、Tomcat。互操作性也存在问题。首先,必须手动修改每个 wsdl。所有<s:schema> <s:any> are replaced with single <s:any>
. 这样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 元素。我确信我通过删除<s:schema>
或使用 wsld2java 时在某处犯了错误,因此它失去了语义。但是我应该在 CXF 中具体做什么,才能使 Java 类看起来像 CSharp 的一样干净?
谢谢你。
编辑:在http://msdn.microsoft.com/en-us/magazine/cc188755.aspx获得了一些线索,我希望这个链接在以后有人搜索相同答案时有效。查找文章的其他方法是:
MSDN 杂志 > 问题 > 2003 > 四月 > XML 文件:Web 服务和数据集