代码之家  ›  专栏  ›  技术社区  ›  matja

Mono wsdl实用程序无法为其SOAP API处理易趣的wsdl文件

  •  1
  • matja  · 技术社区  · 16 年前

    我在尝试处理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]
    

    <xs:any ... <xs:any namespace="##other" ... -这当然使Mono的wsdl实用程序能够处理该文件,并从中生成一个.cs文件。但是当我尝试实例化webservice helper类时,我从我的C#程序中得到一个运行时异常( eBayAPIInterfaceService service = new eBayAPIInterfaceService(); ) :

    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 ---
    

    Web服务描述语言实用程序 Mono Framework v2.0.50727.1433

    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文件是 here

    1 回复  |  直到 16 年前
        1
  •  1
  •   dtb    16 年前

    我不知道这是否解决了你的问题,但是 xs:any wildcard 在你的问题中缺少两个 '#'

    <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 返回一个数组的字段 XmlElement XmlNode 物体。根据对象是被序列化还是反序列化,此类字段可以以两种方式使用。序列化时,对象生成为XML元素或节点,即使它们在被序列化的对象中没有相应的成员。如果指定 Name 属性值应用属性时,所有 XmlElement XmlNode 插入到数组中的对象必须具有相同的元素名称和默认命名空间,否则会引发异常。 如果你设定 Namespace 属性值,则必须设置 ,以及 XmlElement XmlNode 名称 值,则 XmlElement XmlNode 对象可以有任何元素名称。

    名称空间 属性值:

    [System.Xml.Serialization.XmlAnyElement]