Mono wsdl 实用程序无法处理 eBay 的 SOAP API 的 WSDL 文件
-
12-09-2019 - |
题
我在尝试处理 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 ...
到 <xs:any namespace="##other" ...
- 这无疑使得 Mono 的 wsdl 实用程序能够处理该文件,并从中创建 .cs 文件。但是当我尝试实例化 webservice 帮助程序类时,我的 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 ---
是 Mono 的 wsdl 工具有问题,还是 eBay 的 WSDL/模式有问题?- 我看到的几个论坛帖子都说 WSDL 与架构不匹配,因此 Mono 正在做正确的事情,但我该如何修复它以便可以从 C# 实例化 Web 服务帮助程序类?
我的工具的版本:
$ WSDL Web服务说明语言实用程序单框架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 文件是 这里
解决方案
我不知道是否能解决你的问题,但 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
到返回XmlElement
或XmlNode
对象的阵列的场。这样的域可以以两种方式使用,这取决于对象是否被序列化或反序列化。当序列,该目的为XML元素或节点生成的,即使它们具有在对象没有对应的构件(或部件)被序列化。如果在应用属性时指定Name
属性值,插入阵列的所有XmlElement
或XmlNode
对象必须有相同的元素名称和默认命名空间,或抛出一个异常。 如果您设置的Namespace
属性值,你必须设置Name
属性以及和XmlElement
或XmlNode
对象还必须具有相同的名称和命名空间值。如果没有指定Name
值,则XmlElement
或XmlNode
对象可以有任何元素名称。
所以我猜的解决方案是简单地去掉Namespace
属性值:
[System.Xml.Serialization.XmlAnyElement]