Axis2:避免“意外子元素"将非必需属性添加到 WSDL 时出错 [英] Axis2: Avoid "Unexpected subelement" error when non-required property added to WSDL

查看:19
本文介绍了Axis2:避免“意外子元素"将非必需属性添加到 WSDL 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .NET WCF 服务和一个使用 Axis2 生成服务存根的 Java 应用程序.当我向 WCF 中的数据协定添加 可选 属性并在属性列表末尾对其进行排序(这应该是向后兼容的更改)时,它会导致 意外子元素 错误.修复它的唯一方法是在 Axis2 中重新生成存根并重新部署 Java 应用程序——这在我的情况下是不可接受的方法.

I have a .NET WCF service and a Java app that uses Axis2 to generate service stubs. When I add an optional property to a data contract in WCF and sort it at the end of the property list (which should be a backwards-compatible change) it causes Unexpected subelement errors in the Java app. The only way to fix it is to regenerate the stubs in Axis2 and redeploy the Java app -- not an acceptable approach in my case.

需要明确的是,我没有更改属性的顺序并且 WSDL 是有效的.以下是来自之前(Java 应用程序工作时)和之后(导致意外子元素"错误)的 WSDL 类型示例:

To be clear, I have not changed the order of the properties and the WSDL is valid. Here's an example of a type from the WSDL from before (when the Java app worked) and after (which causes the "Unexpected subelement" error):

<!-- BEFORE -->
<xs:complexType name="MyObject">
   <xs:sequence>
      <xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
   </xs:sequence>
</xs:complexType>

<!-- AFTER -->
<xs:complexType name="MyObject">
   <xs:sequence>
      <xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
      <xs:element minOccurs="0" name="MyNewProperty" nillable="true" type="xs:string"/>
   </xs:sequence>
</xs:complexType>

AFTER 版本导致此错误:org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://mycompany.com/services/}MyNewProperty

The AFTER version causes this error: org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://mycompany.com/services/}MyNewProperty

我们可以用 Axis2 做些什么来防止这种情况发生?如果没有,我们是否应该在 WSDL 或 WCF 方面做一些不同的事情?

Is there something we can do with Axis2 to prevent this from happening? If not, is there something different we should do in the WSDL or on the WCF side?

推荐答案

从 XML Schema 的角度来看,这似乎不是向后兼容的更改.如果我要求 XSV 验证消息

It appears that this is not a backwards-compatible change from the point of view of the XML Schema. If I ask XSV to validate a message

<MyObject>
    <Name>Primus Secundus</Name>
    <MyNewProperty>Addita notitia</MyNewProperty>
</MyObject> 

针对您的 <!-- BEFORE --> 架构,我收到一条错误消息,指出 MyNewProperty 无效:

against your <!-- BEFORE --> schema, I get an error indicating that the MyNewProperty is invalid:

每个 cvc-complex-type.1.2.4 无效:元素 {None}:MyNewProperty not在元素 {None}:MyObject 中允许此处 (2),期望 [$]:

Invalid per cvc-complex-type.1.2.4: element {None}:MyNewProperty not allowed here (2) in element {None}:MyObject, expecting [$]:

我在 XML 架构文档中找不到任何内容 (http://www.w3.org/TR/xmlschema-1/) 或 SOAP 版本 (http://www.w3.org/TR/soap/) 表示应该允许使用新元素扩展序列以获得新属性.

I can't find anything in the XML Schema documentation (http://www.w3.org/TR/xmlschema-1/) or in either SOAP version (http://www.w3.org/TR/soap/) which indicates that extending a sequence with new elements for new properties should be allowed.

我在 http://www.w3.org/2001/03/使用了 XSVwebdata/xsv,并将数据上传到以下包装器中:

I used XSV at http://www.w3.org/2001/03/webdata/xsv, and uploaded the data in the following wrapper:

<?xml version="1.0"?>
<wrapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="#mySchema">
    <xs:schema id="mySchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="wrapper">
            <xs:complexType>
                <xs:sequence>
                    <xs:any/>
                    <xs:element name="MyObject" type="MyObject"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
        <!-- BEFORE -->
        <xs:complexType name="MyObject">
            <xs:sequence>
                <xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:schema>
    <MyObject>
        <Name>Primus Secundus</Name>
        <MyNewProperty>Addita notitia</MyNewProperty>
    </MyObject> 
</wrapper>

这篇关于Axis2:避免“意外子元素"将非必需属性添加到 WSDL 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆