开发者

System.InvalidOperationException : XmlSerializer attribute System.Xml.Serialization.XmlChoiceIdentifierAttribute is not valid in Item

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 gener开发者_运维问答ated 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.


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

svcutil /wrapped /serializer:XmlSerializer http://wsdl_url/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜