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

时间:2021-07-02 17:15:50

I have been tasked to send data to a 3rd Party web service, they have provided a test service that is proven to work with a Java client, however, it doesn't in .Net.

我的任务是将数据发送到第三方Web服务,他们提供的测试服务已被证明可以与Java客户端一起使用,但是,它不在.Net中。

When I generate the service proxy and either instantiate the service or serialise the request object, I get the following error:

当我生成服务代理并实例化服务或序列化请求对象时,我收到以下错误:

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[]'

The 3rd Party that sent us this service uses Java, and they had no problem generating the service proxy from the test service. My understanding so far is that there is a bug in .Net (see here) generating the XSD for the WSDL file.

向我们发送此服务的第三方使用Java,他们从测试服务生成服务代理没有问题。到目前为止,我的理解是.Net(见此处)中存在一个错误,为WSDL文件生成XSD。

In the answer here, it mentions modifying the generated XSD with dummy attributes, so I added the dummy attribute as suggested:

在这里的答案中,它提到用虚拟属性修改生成的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>

The only thing adding the dummy attribute achieved was to reduce the compile time of the project from minutes to seconds.

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

Other than this, VS2008 didn't seem to notice the changes - I still can't serialise the object or instantiate the service without getting the exception mentioned above, what am I missing or doing wrong?

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

2 个解决方案

#1


7  

You have to change the XSD file as in my question, but you ALSO have to modify the Reference.cs (or .vb) file in the same folder - I did a find replace on [][] with [] (or ()() with () in vb.net).

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

In all the reading I've done, no answers have said to do both, so I just missed the point - I hope this answer helps others.

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

#2


5  

You are correct, it is a bug in the WSDL tool. To correct the bug you should open the generated files and change some of the 'TestStarXML.wsStarService.VSOptionConflictSetType' to 'TestStarXML.wsStarService.VSOptionConflictSetType[]'.

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

When running you can easly find which ones. When you have changed the types, you service will run fine.

在跑步时,您可以轻松找到哪些。更改类型后,您的服务将正常运行。

#1


7  

You have to change the XSD file as in my question, but you ALSO have to modify the Reference.cs (or .vb) file in the same folder - I did a find replace on [][] with [] (or ()() with () in vb.net).

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

In all the reading I've done, no answers have said to do both, so I just missed the point - I hope this answer helps others.

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

#2


5  

You are correct, it is a bug in the WSDL tool. To correct the bug you should open the generated files and change some of the 'TestStarXML.wsStarService.VSOptionConflictSetType' to 'TestStarXML.wsStarService.VSOptionConflictSetType[]'.

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

When running you can easly find which ones. When you have changed the types, you service will run fine.

在跑步时,您可以轻松找到哪些。更改类型后,您的服务将正常运行。