我正在使用“WSDL Importer”向导将WSDL文件导入Delphi 2010. WSDL文件包含一些Delphi完全忽略的“attributeGroup”标签,这可能是一个bug,虽然我还没有在Quality Central上找到关于这个问题的条目,只在here和here这样的论坛中提到过.
我的问题有几个部分:
>什么是最好的解决方法?
>我编写了一个Python脚本来格式化WSDL文件,以便对attributeGroup标签的所有引用都替换为attributeGroups中定义的属性的声明;换句话说,展平参考文献.输出通过“WSDL导入器”向导成功导入Delphi,看起来正确,但我还没有测试通过这个新的WSDL文件构造的消息是否能正常工作.这种策略是否可行,或者我现在应该放弃并转向其他更有效的方法?
更新
根据我的经验和这个问题的答案,我决定使用C#控制台应用程序进行包装路由,该应用程序使用JSON输入数据并输出JSON应答数据. Delphi应用程序驱动C#应用程序.整个事物的SOAP部分现在毫不费力,并且在C#.NET中“正常工作”,其余功能由Delphi很好地处理.我会向其他有类似问题的人推荐这条路线.我确实尝试将C#SOAP程序集导出为COM库,并从Delphi连接到它,但它变得非常复杂,因为我的特定应用程序中的SOAP规范很大而且有点复杂.
解决方法
根据this post,在导入wsdl文件时,.NET wsdl.exe工具无法识别某些标记.根据MSDN:
attributeGroup: Ignored. DataContractSerializer does not support use of xs:group,xs:attributeGroup,and xs:attribute. These declarations are ignored as children of xs:schema,but cannot be referenced from within complexType or other supported constructs.
在MSDN blogs之一上也描述了这种行为(尽管以一种非常难以理解的方式).在我的具体情况中,导致问题的wsdl文件的特定部分如下所示:
<xs:complexType name="PhonesType"> <xs:annotation> <xs:documentation xml:lang="en">Provides detailed phone information.</ xs:documentation> </xs:annotation> <xs:sequence> <xs:element maxOccurs="unbounded" name="Phone"> <xs:annotation> <xs:documentation xml:lang="en">Used to pass detailed phone information.</xs:documentation> </xs:annotation> <xs:complexType> <xs:attributeGroup ref="TelephoneInfoGroup"/> <xs:attributeGroup ref="ID_OptionalGroup"> <xs:annotation> <xs:documentation xml:lang="en">The ID attribute in this group is a unique identifying value assigned by the creating system and may be used to reference a primary-key value within a database or in a particular implementation.</xs:documentation> </xs:annotation> </xs:attributeGroup> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType>
似乎< xs:attributeGroup ref =“TelephoneInfoGroup”/>正在被.NET wsdl.exe工具忽略,就像它被Delphi wsdl导入器忽略一样.在这种情况下,在Delphi和.NET中导入失败的情况下,可能必须更改wsdl文件,这意味着我将不得不使用我自己的python ref-flattener.