我怎样才能正确地修改生成的XSD克服一个已知的.Net错误会导致异常和QUOT; cs0030:无法生成临时类"正确地、异常、错误、XSD

2023-09-03 06:23:48 作者:静待另一片天

我的职责,以数据发送到第三方网络服务,他们提供了被证明与Java客户端工作测试服务,然而,它没有在净

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.

当我生成服务代理,要么实例化服务或连载的请求对象,我得到以下错误:

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

第三方发送我们的这项服务使用Java,他们也没有问题产生的测试服务的服务代理。我的理解,到目前为止是,有在.net中的错误(见这里)生成XSD的WSDL文件。

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.

在这里答案,它提到修改生成的XSD与虚拟的属性,所以我增加了虚拟属性的建议

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

<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.

除此之外,VS2008似乎没有注意到的变化 - 我仍然无法序列化对象或没有得到除上面提到的,我丢失或做错了

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?

推荐答案

您必须更改XSD文件在我的问题,但你也必须修改Reference.cs(或.vb)文件相同的文件夹 - 我没有一个找到替换[] [用[](或()()和()在vb.net)。

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).

在所有的阅读我所做的,没有答案都表示做两件事,所以我只是忽略了一点 - 我希望这个答案可以帮助别人

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.

 
精彩推荐
图片推荐