Dot-Net
如何正確修改生成的 XSD 以克服導致異常“cs0030:無法生成臨時類”的已知 .Net 錯誤
我的任務是向第 3 方 Web 服務發送數據,他們提供了一個測試服務,該服務被證明可以與 Java 客戶端一起使用,但是,它不在 .Net 中。
當我生成服務代理並實例化服務或序列化請求對象時,我收到以下錯誤:
Unable to generate a temporary class (result=1). error CS0030: Cannot convert type 'TestStarXML.wsStarService.VSOptionInclusiveSetType[]' to 'TestStarXML.wsStarService.VSOptionInclusiveSetType' error CS0030: Cannot convert type 'TestStarXML.wsStarService.VSOptionConflictSetType[]' to 'TestStarXML.wsStarService.VSOptionConflictSetType' error CS0030: Cannot convert type 'TestStarXML.wsStarService.ColorRequirementSetType[]' to 'TestStarXML.wsStarService.ColorRequirementSetType' error CS0030: Cannot convert type 'TestStarXML.wsStarService.ColorExclusionSetType[]' to 'TestStarXML.wsStarService.ColorExclusionSetType' error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.VSOptionInclusiveSetType' to 'TestStarXML.wsStarService.VSOptionInclusiveSetType[]' error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.VSOptionConflictSetType' to 'TestStarXML.wsStarService.VSOptionConflictSetType[]' error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.ColorRequirementSetType' to 'TestStarXML.wsStarService.ColorRequirementSetType[]' error CS0029: Cannot implicitly convert type 'TestStarXML.wsStarService.ColorExclusionSetType' to 'TestStarXML.wsStarService.ColorExclusionSetType[]'向我們發送此服務的第 3 方使用 Java,他們從測試服務生成服務代理沒有問題。到目前為止,我的理解是 .Net 中存在一個錯誤(請參見此處)為 WSDL 文件生成 XSD。
在此處的答案中,它提到使用虛擬屬性修改生成的 XSD,因此我按照建議添加了虛擬屬性:
<xs:complexType name="VSInclusivesOptionType"> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="VSOptionInclusiveSet" type="tns:VSOptionInclusiveSetType" /> </xs:sequence> <xs:attribute name="tmp" type="xs:string" /> <!-- this is all I have added (for each of the types in the exception message) --> </xs:complexType> <xs:complexType name="VSOptionInclusiveSetType"> <xs:sequence> <xs:element minOccurs="0" name="SetID" type="ns2:IdentifierType" /> <xs:element minOccurs="0" name="NumberOfOptionsNumeric" type="xs:decimal" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="VSOption2" type="tns:VSOption2Type" /> </xs:sequence> </xs:complexType>添加 dummy 屬性的唯一實現是將項目的編譯時間從幾分鐘減少到幾秒鐘。
除此之外,VS2008 似乎沒有註意到這些變化——如果沒有上述異常,我仍然無法序列化對像或實例化服務,我錯過了什麼或做錯了什麼?
您必須按照我的問題更改 XSD 文件,但您還必須修改同一文件夾中的 Reference.cs(或 .vb)文件 - 我做了一個查找替換
$$ $$$$ $$和$$ $$(或()()與()在vb.net)。 在我所做的所有閱讀中,沒有答案說兩者都可以,所以我只是錯過了重點 - 我希望這個答案對其他人有所幫助。
你是對的,這是 WSDL 工具中的一個錯誤。要更正錯誤,您應該打開生成的文件並將一些“TestStarXML.wsStarService.VSOptionConflictSetType”更改為“TestStarXML.wsStarService.VSOptionConflictSetType”
$$ $$’. 執行時,您可以輕鬆找到哪些。更改類型後,您的服務將正常執行。