Mono wsdl 实用程序无法处理 eBay 的 SOAP API 的 WSDL 文件

发布于 2024-08-05 17:40:13 字数 4912 浏览 7 评论 0 原文

我在尝试处理 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 中搜索解决方案后发现,建议将以 开头的元素更改为 - 这无疑使 Mono 的 wsdl 实用程序能够处理该文件,并从中创建 .cs 文件。但是,当我尝试实例化 Webservice 帮助程序类(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 文件是 此处

I'm getting this error from Mono's wsdl utility while trying to process eBay's WSDL file -

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

Searching Google for solutions reveals a suggestion of changing elements that start with <xs:any ... to <xs:any namespace="##other" ... - this certainly makes Mono's wsdl utility able to process the file, to make a .cs file out of it. But then I get a runtime exception from my C# program when I try to instantiate the webservice helper class ( 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 ---

Is Mono's wsdl tool at fault here, or eBay's WSDL/schema? - several forum posts I've seen say that the WSDL doesn't match the schema, so Mono is doing the right thing, but how do I fix it so I can instantiate the webservice helper class from C#?

Versions of my tools :

$ wsdl
Web Services Description Language Utility
Mono Framework v2.0.50727.1433

$ gmcs --version
Mono C# compiler version 2.4.2.3

Generated code for 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;
        }
    }
}

The eBayAPIInterfaceService.cs file which wsdl generates after my 'fix' is here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欲拥i 2024-08-12 17:40:13

我不知道这是否能解决您的问题,但是 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 属性,以及 XmlElement 或 < code>XmlNode 对象还必须具有相同的名称和命名空间值。如果未指定 Name 值,则 XmlElementXmlNode 对象可以具有任何元素名称。

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

[System.Xml.Serialization.XmlAnyElement]

I don't know if this solves your problem, but the xs:any wildcard in your question is missing two '#':

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

The generated C# code contains lots of definitions like this:

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

From MSDN:

Apply the XmlAnyElementAttribute to a field that returns an array of XmlElement or XmlNode objects. Such a field can be used in two ways, depending on whether an object is being serialized or deserialized. When serialized, the object is generated as XML elements or nodes, even though they have no corresponding member (or members) in the object being serialized. If you specify a Name property value when applying the attribute, all XmlElement or XmlNode objects inserted into the array must have the same element name and default namespace, or an exception is thrown. If you set the Namespace property value, you must set the Name property as well, and the XmlElement or XmlNode objects must also have the same name and namespace values. If no Name value is specified, the XmlElement or XmlNode objects can have any element name.

So I'd guess the solution is to simply remove the Namespace property values:

[System.Xml.Serialization.XmlAnyElement]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文