“无法识别指定的类型”尝试调用 Web 服务时出现异常

发布于 2024-09-04 17:27:21 字数 2333 浏览 1 评论 0原文

我正在尝试使用 WSE 3.0 作为 Visual Studio 2005 中的客户端来调用第三方 Web 服务。

调用工作正常,我可以看到我得到了良好的响应(我启用了跟踪),但显然 xml 解析器对此感到窒息。我总是收到 InvalidOperationException

XML 文档中有错误。

带有 InnerException

无法识别指定的类型:name='Map',namespace='http://xml .apache.org/xml-soap',位于

这是响应的相关部分:

 <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>

这就是 wsdl 中定义“bevoegdheid”的方式:

  <xsd:element name="bevoegdheid" type="soap-enc:Array" /> 

wsdl 中的任何地方都没有提到“Map”类型。

我一直在谷歌上搜索这个问题,但我找到的唯一答案是类似于

该服务使用 rpc/编码格式,很难实现互操作性。如果您可以将服务器更改为文档/文字,那就更好了。

但由于这是第三方服务(已被其他客户使用),因此我们没有选择。

还有其他建议吗?如何让 xml 解析器识别“Map”类型?

I'm trying to call a third party webservice using WSE 3.0 as a client in Visual Studio 2005.

The call works fine and I can see that I get a good response (I have tracing enabled), but apparently the xml parser chokes over it. I always get an InvalidOperationException:

There is en error in the XML document.

with an InnerException:

The specified type was not recognized: name='Map', namespace='http://xml.apache.org/xml-soap', at <bevoegdheid xmlns=''>.

This is the relevant part of the response:

 <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>

And this is how that "bevoegdheid" is defined in the wsdl:

  <xsd:element name="bevoegdheid" type="soap-enc:Array" /> 

There is no mention of a "Map" type anywhere in the wsdl.

I have been googling around for this, but the only kind of answer I've found is something along the lines of

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.

But as this is a third party service (which is already used by other clients), this is no option for us.

Any other suggestions? How can I get the xml parser to recognize that "Map" type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬色的秋千 2024-09-11 17:27:21

首先,下载 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 是继承对象的类型。

希望它对某人有帮助,祝你好运:)。

First of all, download SOAPUI and validate the wsdl, your request and the response. If anything is wrong on their side, tell them to validate their webservice themselves and fix it. If the webservice does not conform to the WS-I Basic Profile, I'd say don't even waste your time.


And if you still can't fix it, the following might point you in the right direction.

I've gotten similar exception while deserializing xml and soap responses but since you haven't provided a lot of details I don't really know your specific implementation. So this might be useful to you, or not at all :/.

My problem was caused by objects in the xml that are inherited types. Apparently the XmlSerializer can't cope with that without some additional instructions.

Example (C#):

My xml contained objects of type Function and some of types that inherit from Function.
Because of this, the normal syntax for creating an XMLSerializer wouldn't work.

XmlSerializer Serializer = new XmlSerializer(typeof(MyCustomObject);

Apparently the serializer needs some extra instructions, like so:

XmlSerializer Serializer = new XmlSerializer(typeof(MyCustomObject), new Type[] {typeof(Function.InheritedType1), typeof(Function.InheritedType2), typeof(Function.InheritedType3), typeof(Function.InheritedType4) });

Where InheritedType is the type of the inherited object.

Hope it helps someone, good luck :).

不必你懂 2024-09-11 17:27:21

这里可能存在一些问题。其中之一可能是以下内容:

<bevoegdheid SOAP-ENC:arrayType="ns1:Map[2]" xsi:type="SOAP-ENC:Array">

在肥皂消息中。解析器可能不喜欢这样的事实:“bevoegdheid”元素的 WSDL 类型属性定义与肥皂消息中该元素的 xsi:type 值之间存在大小写不匹配的情况。此问题可能会导致您看到的实际(有些误导性)异常。我不知道如何修复类似的问题,因为你不控制任何一个组件。

异常消息表明“ns1:Map[2]”的 arrayType 值不是 ns1 命名空间的有效元素名称。该命名空间应该在 XSD 中为“http://xml.apache.org/xml-soap”定义”,但看起来并非如此。不幸的是,根本问题可能是服务生成的肥皂消息似乎与服务的 WSDL 不一致。祝你好运!

There may be a couple of problems here. One maybe the following:

<bevoegdheid SOAP-ENC:arrayType="ns1:Map[2]" xsi:type="SOAP-ENC:Array">

in the soap message. The parser may not like the fact that there is a case mismatch between the WSDL type attribute definition for the "bevoegdheid" element and the xsi:type value of the element in the soap message. This issue may cause the actual (somewhat misleading) exception you're seeing. I'm not sure how to fix something like that since you don't control either component.

The exception message is saying the arrayType value of "ns1:Map[2]" is not a valid element name of the ns1 namespace. That namespace is should be defined in the XSD for "http://xml.apache.org/xml-soap" but it appears it isn't. Unfortunately, the fundamental problem may be that the service is generating soap messages that don't appear to be consistent with the WSDL for the service. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文