我正在尝试使用 WSE 3.0 作为 Visual Studio 2005 中的客户端来调用第三方 Web 服务。
调用工作正常,我可以看到我得到了良好的响应(我启用了跟踪),但显然 xml 解析器对此感到窒息。我总是收到 InvalidOperationException
:
There is en error in the XML document.
带有InnerException
:
The specified type was not recognized: name='Map', namespace='http://xml.apache.org/xml-soap', at <bevoegdheid xmlns=''>.
这是响应的相关部分:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="https://acceptatie.cartalk.nl/Soap/Apk" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:opvragenKeurmeesterGegevensResponse>
<opvragenKeurmeesterGegevensReturn xsi:type="ns2:Backend_Apk_Result_OpvragenKeurmeesterGegevens">
<naam xsi:type="xsd:string">A name</naam>
...
<bevoegdheid SOAP-ENC:arrayType="ns1:Map[2]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns1:Map">
<item>
<key xsi:type="xsd:string">soortBevoegdheid</key>
<value xsi:type="xsd:string">AL</value>
</item>
...
</item>
<item>
...
</item>
</bevoegdheid>
<meldingSoort xsi:nil="true" />
<meldingNummer xsi:nil="true" />
<melding xsi:nil="true" />
</opvragenKeurmeesterGegevensReturn>
</SOAP-ENV:opvragenKeurmeesterGegevensResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这就是“bevoegdheid”在 wsdl 中的定义方式:
<xsd:element name="bevoegdheid" type="soap-enc:Array" />
wsdl 中的任何地方都没有提到“Map”类型。
我一直在谷歌上搜索这个问题,但我找到的唯一答案是类似于
The service uses rpc/encoded format which is harder to get interoperability with. If you can change the server to document/literal it is better.
但由于这是第三方服务(已被其他客户使用),因此我们没有选择。
还有其他建议吗?如何让 xml 解析器识别“Map”类型?
最佳答案
首先,下载 SOAPUI 并验证 wsdl、您的请求和响应。如果他们这边有任何问题,请告诉他们自己验证他们的网络服务并修复它。如果 Web 服务不符合 WS-I Basic Profile,我建议不要浪费时间。
如果您仍然无法解决问题,下面的可能会为您指明正确的方向。
我在反序列化 xml 和 SOAP 响应时遇到了类似的异常,但由于您没有提供大量详细信息,我真的不知道您的具体实现。所以这可能对你有用,或者根本没有用:/.
我的问题是由 xml 中继承类型的对象引起的。显然,如果没有一些额外的指令,XmlSerializer 就无法处理这个问题。
示例(C#):
我的 xml 包含 Function
类型的对象以及一些从 Function 继承的类型。
因此,创建 XMLSerializer 的常规语法将不起作用。
XmlSerializer Serializer = new XmlSerializer(typeof(MyCustomObject);
显然序列化器需要一些额外的指令,如下所示:
XmlSerializer Serializer = new XmlSerializer(typeof(MyCustomObject), new Type[] {typeof(Function.InheritedType1), typeof(Function.InheritedType2), typeof(Function.InheritedType3), typeof(Function.InheritedType4) });
其中InheritedType
是继承对象的类型。
希望它对某人有帮助,祝你好运:)。
关于xml-serialization - "The specified type was not recognized"尝试调用 Web 服务调用时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2997305/