我在尝试处理 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 文件在这里