使用 MS/.NET/.asmx webservice 时如何在 Java/JAXB/CXF 端生成业务 POJO?

发布于 2024-12-01 04:29:07 字数 2076 浏览 1 评论 0原文

我们有几个基于 MS 的 Web 服务,在 Intranet 中显示为 .asmx?WSDL 链接。当使用最新的 Visual Studio 使用此 Web 服务时,没有问题。所有业务对象都有意义。我怀疑 Microsoft 在使用 ServiceReference 时使用了一些秘密握手,并且依赖于一些关于类型为 的元素背后的实际 CSharp 类型的专有知识,

但是我们部门需要使用 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>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;any/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你丑哭了我 2024-12-08 04:29:07

答:不可能。

经过详尽的研究,很明显,当服务端没有 Business CSharp 对象时,Business POJO 是不可能在客户端重建的。就这么简单。

在我的特殊情况下:

  • CXF 2.4.2 wsdl2java 消耗 ASMX ASP.NET 将给出 s:schema 错误:FAIL
  • SOAPUI with CXF 2.4.2 will FAIL 出于同样的原因
  • Oracle Sun Metro Glassfish 3.1 wsimport 消耗 ASMX ASP.NET 将需要本地副本模式数量:PASS(但需要 WSDL 的本地副本,并且仍然没有业务对象)

将来最好的场景是:

  • Oracle Sun WSIT Tango 通过额外的“秘密握手”来使用 Microsoft WCF 服务,以便在使用时和运行时期间传递一些元信息。

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:

  • CXF 2.4.2 wsdl2java consuming ASMX ASP.NET will give s:schema error: FAIL
  • SOAPUI with CXF 2.4.2 will FAIL for same reason
  • Oracle Sun Metro Glassfish 3.1 wsimport consuming ASMX ASP.NET will need a local copies of schemas: PASS (but needs a local copy of WSDL, and still no business objects)

In future, the best scenario is:

  • Oracle Sun WSIT Tango consumes Microsoft WCF service with extra "secret handshake" to deliver some metainformation both during consume-time and run-time.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文