8

I have been trying to connect to some web services using WCF but I keep getting an error when I try to call the function I need.

This is the error I'm getting:

System.InvalidOperationException : XmlSerializer attribute System.Xml.Serialization.XmlChoiceIdentifierAttribute is not valid in Item. Only XmlElement, XmlArray, XmlArrayItem, XmlAnyAttribute and XmlAnyElement attributes are supported when IsWrapped is true.

The error happens before it even gets to calling the actual service and it doesn't even occur because of the method I'm trying to call. The issue is with another method that's defined in the WCF generated class.

I have been able to trace the issue to a section of code in the XSD that is used to define the WSDL:

<xs:choice minOccurs="0">
<xs:element name="additionalSocInd" type="tns:BinaryExpressionType"/>
<xs:element name="skipServiceValidationInd" type="tns:BinaryExpressionType"/>
</xs:choice>

The corresponding generated code:

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")]
[System.SerializableAttribute()]   [System.Xml.Serialization.XmlTypeAttribute(Namespace="http:integration.sprint.com/interfaces/manageSubscriberServices/v1/manageSubscr" +
    "iberServices.xsd", IncludeInSchema=false)]
public enum ItemChoiceType2
{
    additionalSocInd,
    skipServiceValidationInd,
}

When I comment out the above enum and all references to it, the service works. There are other xs:choice statements in the XSD that don't seem to cause any problems.


Update: Further investigation revealed that when you have the following:

The element is defined directly inside of a sequence element:

<xs:sequence>
<xs:element ... />
...
<xs:choice minOccurs="0">
<xs:element name="additionalSocInd" type="tns:BinaryExpressionType" />
<xs:element name="skipServiceValidationInd" type="tns:BinaryExpressionType" />
</xs:choice>
...
<xs:element ... />
</xs:sequence>

The proxy generated by svcutil causes the error noted above.

When changed to look like this:

<xs:sequence>
<xs:element ... />
...
<xs:element minOccurs="0" name="myChoiceType" type="tns:MyChoiceType" />
...
<xs:element ... />
</xs:sequence>
<xs:complexType name="MyChoiceType">
<xs:choice>
<xs:element name="additionalSocInd" type="tns:BinaryExpressionType" />
<xs:element name="skipServiceValidationInd" type="tns:BinaryExpressionType" />
</xs:choice>
</xs:complexType>

The error goes away. So it may be a bug with the code the generator (svcutil) generates.


I will need to call all the methods in the WSDL, so commenting out the ones that don't work isn't an option. And I need to get it working without changing the WSDL (which is the client's, not ours). Any help would be appreciated.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
criel
  • 138
  • 1
  • 6
  • Given that you can't change the WSDL and SvcUtil won't correctly parse that XSD in that WSDL, it seems your only realistic choice is to create the client code by giving SvcUtil your edited version of the WSDL. If that client code works correctly with the service then you'll need to go through the same manual process each time the WSDL changes. My guess is if there exists a "bug" it's most likely in the XSD of your client's WSDL than in the SvcUtil XSD parsing logic :) – Sixto Saez Sep 09 '11 at 17:38
  • Please don't add "WCF & C# - " to your titles. The tags already categorize the question. – John Saunders Sep 09 '11 at 19:30

1 Answers1

8

Try to generate the proxy from command line with these flags:

svcutil /wrapped /serializer:XmlSerializer http://wsdl_url/
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158
  • Thanks Yaron! The /wrapped flag did it. I really appreciate your help on this! – criel Sep 14 '11 at 22:38
  • I'm using .Net 3.5, the svcutil documentation mentions /wrapped, but when I try to use it, it says /wrapped is unrecognised. Any idea's? – Mr Shoubs May 30 '12 at 12:34