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

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

问题描述

我有一个.NET WCF服务和一个使用Axis2生成服务存根的Java应用程序.当我在WCF中向数据合约添加 optional 属性并在属性列表的末尾对其进行排序(应该是向后兼容的更改)时,会导致意外的子元素"错误.修复此错误的唯一方法是在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有效.这是一个来自WSDL的类型的示例,该类型来自之前(Java应用程序工作时)和之后(这会导致意外子元素"错误):

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:意外的子元素{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> 

针对您的<!-之前->模式,我收到一条错误消息,指示MyNewProperty无效:

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

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

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

我在XML Schema文档中找不到任何内容( 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/上使用了XSV webdata/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天全站免登陆