How can I correctly modify a generated XSD to over

2020-07-06 08:13发布

问题:

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

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.

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.

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?

回答1:

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.



回答2:

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

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