"The specified type was not recognized" exception when trying to invoke a webservice call
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), th开发者_StackOverflow社区is is no option for us.
Any other suggestions? How can I get the xml parser to recognize that "Map" type?
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 (bunch of amateurs!). 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 :).
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!
精彩评论