2009-09-20 101 views
1

我從Mono的WSDL工具在嘗試處理eBay的WSDL文件收到此錯誤 -單WSDL工具無法處理eBay的WSDL文件的SOAP API

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文件。但後來我從我的C#程序得到一個運行時異常,當我嘗試實例化Web服務輔助類(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 --- 

在故障單的WSDL工具在這裏,或eBay的WSDL /架構? - 我見過的幾篇論壇帖子都說WSDL與模式不匹配,所以Mono做的是正確的事情,但我該如何解決它,以便我可以實例化C#中的webservice輔助類?我的工具

版本:

$ WSDL Web服務描述語言工具 單框架v2.0.50727.1433

$的GMC --version 單聲道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; 
     } 
    } 
} 

eB之後我的「修復」該WSDL產生ayAPIInterfaceService.cs文件here

+0

如何爲'ErrorParameterType.Any'生成的代碼是什麼樣子? – dtb 2009-09-20 14:56:27

+0

@dtb:我已經將ErrorParameterType的定義添加到問題文本中,我無法在源代碼中找到「ErrorParameterType.Any」。我已經添加了一個鏈接到正在生成的完整.cs文件。該鏈接的Makefile和我的test.cs在同一個目錄中。 – matja 2009-09-20 15:29:24

+0

'Namespace =「」'似乎是罪魁禍首;我在MSDN上找到了一個報價(請參閱我的答案)。 – dtb 2009-09-20 15:48:10

回答

1

我不知道是否能解決你的問題,但你的問題是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應用於返回XmlElementXmlNode對象的數組的字段。根據對象是序列化還是反序列化,這種字段可以以兩種方式使用。在序列化時,即使對象中沒有對應的成員(或成員)被序列化,該對象也會生成爲XML元素或節點。如果在應用屬性時指定Name屬性值,則插入到數組中的所有對象XmlElementXmlNode必須具有相同的元素名稱和默認名稱空間,否則將拋出異常。 如果您設置Namespace屬性值,則必須設置Name屬性以及,並且XmlElementXmlNode對象也必須具有相同的名稱和名稱空間值。如果未指定Name值,則XmlElementXmlNode對象可以具有任何元素名稱。

所以我猜的解決方案是簡單地去掉Namespace屬性值:

[System.Xml.Serialization.XmlAnyElement] 
+0

好點 - 這是我犯的一個錯誤,我確實嘗試了「## other」 - 這使得wsdl工具很開心,但是當運行我的簡單C#程序來實例化webservice幫助類時,我仍然遇到了運行時異常 – matja 2009-09-20 14:54:24

+0

@ dtb:感謝關於刪除名稱空間屬性值的建議,這當然似乎修復了我得到的運行時異常,但是現在我得到一個新的運行時異常:「未處理的異常:System.InvalidOperationException:在eBayAPIInterfaceService類中找不到成員RequesterCredentialsField。 「 - 這很奇怪,因爲RequesterCredentialsField是eBayAPIInterfaceService中的第一個成員。我不明白爲什麼它沒有找到它。 – matja 2009-09-20 15:53:47

+0

'RequesterCredentialsField'字段是私人的。 XmlSerialization僅適用於公共屬性/字段,即它應該使用公共'RequesterCredentials'屬性而不是專用字段。 – dtb 2009-09-20 16:02:11