1

我在尝试处理 eBay 的 WSDL 文件时从 Mono 的 wsdl 实用程序收到此错误 -

http://developer.ebay.com/webservices/latest/eBaySvc.wsdl

$ wsdl eBaySvc.wsdl 
Web Services Description Language Utility
Mono Framework v2.0.50727.1433
Error: XmlSchema error: Ambiguous element label which is contained by -any- particle was detected: urn:ebay:apis:eBLBaseComponents:PreferenceLevel Related schema item SourceUri: file:///home/manger/projects/ebay/eBaySvc.orig.wsdl, Line 10296, Position 7.
Stack:
   at System.Xml.Schema.ValidationHandler.RaiseValidationEvent (System.Xml.Schema.ValidationEventHandler handle, System.Exception innerException, System.String message, System.Xml.Schema.XmlSchemaObject xsobj, System.Object sender, System.String sourceUri, XmlSeverityType severity) [0x00000] 
  at System.Xml.Schema.XmlSchemaObject.error (System.Xml.Schema.ValidationEventHandler handle, System.String message, System.Exception innerException, System.Xml.Schema.XmlSchemaObject xsobj, System.Object sender) [0x00000] 
  at System.Xml.Schema.XmlSchemaObject.error (System.Xml.Schema.ValidationEventHandler handle, System.String message) [0x00000]

在 Google 中搜索解决方案会发现更改以<xs:any ... to开头的元素的建议<xs:any namespace="##other" ...——这无疑使 Mono 的 wsdl 实用程序能够处理文件,从而从中生成 .cs 文件。但是,当我尝试实例化 web 服务帮助程序类 ( eBayAPIInterfaceService service = new eBayAPIInterfaceService();) 时,我的 C# 程序出现运行时异常:

Unhandled Exception: System.InvalidOperationException: There was an error reflecting type 'AddDisputeRequestType'. ---> System.InvalidOperationException: There was an error reflecting field 'DetailLevel'. ---> System.InvalidOperationException: There was an error reflecting type 'DetailLevelCodeType'. ---> System.InvalidOperationException: There was an error reflecting type 'System.Object'. ---> System.InvalidOperationException: There was an error reflecting type 'AbstractResponseType'. ---> System.InvalidOperationException: There was an error reflecting field 'Errors'. ---> System.InvalidOperationException: There was an error reflecting type 'ErrorType'. ---> System.InvalidOperationException: There was an error reflecting field 'ErrorParameters'. ---> System.InvalidOperationException: There was an error reflecting type 'ErrorParameterType'. ---> System.InvalidOperationException: There was an error reflecting field 'Any'. ---> System.InvalidOperationException: The element Any has been attributed with an XmlAnyElementAttribute and a namespace '', but no name. When a namespace is supplied, a name is also required. Supply a name or remove the namespace.                                           
  at System.Xml.Serialization.XmlReflectionImporter.ImportAnyElementInfo (System.String defaultNamespace, System.Xml.Serialization.XmlReflectionMember rmember, System.Xml.Serialization.XmlTypeMapMemberElement member, System.Xml.Serialization.XmlAttributes atts) [0x00000]                                                                                            
  at System.Xml.Serialization.XmlReflectionImporter.CreateMapMember (System.Type declaringType, System.Xml.Serialization.XmlReflectionMember rmember, System.String defaultNamespace) [0x00000]                                                   
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000]                                     
  --- End of inner exception stack trace ---

是 Mono 的 wsdl 工具有问题,还是 eBay 的 WSDL/模式有问题?- 我看到的几个论坛帖子说 WSDL 与架构不匹配,所以 Mono 做的事情是正确的,但是我该如何解决它,以便我可以从 C# 实例化 web 服务帮助程序类?

我的工具版本:

$ wsdl Web 服务描述语言实用程序 Mono 框架 v2.0.50727.1433

$ gmcs --version Mono C# 编译器版本 2.4.2.3

为 ErrorParameterType 生成的代码:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.1433")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:ebay:apis:eBLBaseComponents")]
public partial class ErrorParameterType {

    private System.Xml.XmlElement[] anyField165;

    ... more class members follow ...

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElement(Namespace="")]
    public System.Xml.XmlElement[] Any {
        get {
            return this.anyField165;
        }
        set {
            this.anyField165 = value;
        }
    }
}

wsdl 在我的“修复”之后生成的 eBayAPIInterfaceService.cs 文件在这里

4

1 回答 1

1

我不知道这是否解决了您的问题,但是您问题中的xs:any通配符缺少两个'#'

<xs:any namespace="##other" ...
                   ↑

生成的 C# 代码包含很多这样的定义:

[System.Xml.Serialization.XmlAnyElement(Namespace="")]
public System.Xml.XmlElement[] Any {
    get {
        return this.anyFieldXXX;
    }
    set {
        this.anyFieldXXX = value;
    }
}

来自MSDN

将 应用于XmlAnyElementAttribute返回数组XmlElementXmlNode对象的字段。根据对象是被序列化还是反序列化,可以以两种方式使用这样的字段。序列化时,对象作为 XML 元素或节点生成,即使它们在被序列化的对象中没有相应的成员(或多个成员)。如果Name在应用属性时指定属性值,则插入到数组中的所有XmlElementXmlNode对象必须具有相同的元素名称和默认命名空间,否则将引发异常。如果设置Namespace属性值,则必须Name同时设置属性XmlElementXmlNode对象也必须具有相同的名称和命名空间值。如果不Name指定值时,XmlElementXmlNode对象可以具有任何元素名称。

所以我猜解决方案是简单地删除Namespace属性值:

[System.Xml.Serialization.XmlAnyElement]
于 2009-09-20T14:46:21.210 回答