c# - 与 C# : XmlChoiceIdentifierATtribute is not valid in Items 中的 Web 服务通信时遇到问题

标签 c# soap wsdl

有一个WSDL我无法控制的网络服务,我遇到了麻烦;我可以使用 soapUI 与此服务交互并毫无问题地使用添加服务引用 -> 高级 -> 添加 Web 引用。

但是,当我尝试使用标准的添加服务引用方法(添加服务引用,使用从 wsdl.exe 生成的代码进行连接)与其对话时,出现以下错误:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

我读过一些文章说 Java 和 .NET 之间存在一些 SOAP 不兼容性,但是四处搜索我发现几乎没有人遇到这个问题,这让我觉得我一定是做错了什么?

最佳答案

发生的事情是 DataContractSerializer(WCF 的默认设置)无法处理模式(这在非 WCF-WCF 场景中很典型)所以它“回退”并生成一个使用 XmlSerializer。生成与 XmlSerializer 一起使用的代理的“回退”机制可能未以与添加 Web 引用使用的直接到 XmlSerializer 方法一致的方式生成它。

当您转到“Advanced->Add Web Reference”时,您手动告诉 Visual Studio 使用一种机制,该机制直接生成使用 XmlSerializer 的代理,而不是使用回退机制。

关于c# - 与 C# : XmlChoiceIdentifierATtribute is not valid in Items 中的 Web 服务通信时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6185162/

相关文章:

android - Web服务初学者,使用Android

java - 通过 Spring 集成以及 http header 调用 Soap 服务

python - 将 Web 服务与 Python Suds 结合使用时如何修复 unicode 问题

c# - 发送和接收 SOAP 消息

c# - WCF 生成的代理不包含*指定属性标志的 WSDL 字符串字段与 minoccurs ="0"

java - 在 Tomcat 上访问 wsdl

C# XmlWriter.Create() - 访问路径被拒绝

c# - 使用内部构造函数创建泛型类

c# - 如何评论为什么可以忽略捕获

c# - 运行MVVM时,EventHandler为Null