如何正确修改生成的XSD以克服导致异常的已知.Net错误"cs0030:无法生成临时类"

Mr *_*ubs 9 .net xsd web-services exception visual-studio-2008

我的任务是将数据发送到第三方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[]'
Run Code Online (Sandbox Code Playgroud)

向我们发送此服务的第三方使用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>
Run Code Online (Sandbox Code Playgroud)

添加虚拟属性的唯一方法是将项目的编译时间从几分钟缩短到几秒钟.

除此之外,VS2008似乎没有注意到这些变化 - 我仍然无法序列化对象或实例化服务而没有得到上述异常,我错过了什么或做错了什么?

Mr *_*ubs 7

您必须在我的问题中更改XSD文件,但您还必须修改同一文件夹中的Reference.cs(或.vb)文件 - 我在[] []上使用[](或()执行查找替换()with()in vb.net).

在我所做的所有阅读中,没有任何答案可以做到这两点,所以我错过了这一点 - 我希望这个答案可以帮助其他人.


Pet*_*ter 5

你是对的,它是WSDL工具中的一个错误.要纠正错误,您应该打开生成的文件,并将一些'TestStarXML.wsStarService.VSOptionConflictSetType'更改为'TestStarXML.wsStarService.VSOptionConflictSetType []'.

在跑步时你可以很容易地找到哪些.更改类型后,您的服务将正常运行.