简体   繁体   中英

WCF XML deserialization fail

I've got this WSDL(the service is not mine): http://soaptest.webapi-beta.gratka.pl/dom.html?wsdl

When I get response from method "pobierz_kategorie" I get exception like that

CommunicationException Error in deserializing body of reply message for operation 'pobierz_kategorie'. {"There is an error in XML document (2, 501)."} {"The specified type was not recognized: name='kategoria_drzewo', namespace='http://soap.webapi-beta.gratka.pl/dom.html', at ."}

I would like to ask how to modify WSDL or WCF configuration or generated proxy to make it working. When I use PHP to call that method it works so I guess that must be some XMLSerializer problem.

This the response message I get:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soap.webapi-beta.gratka.pl/dom.html" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:pobierz_kategorieResponse>
            <drzewo_kategorii SOAP-ENC:arrayType="ns1:kategoria_drzewo[48]" xsi:type="ns1:drzewo_kategorii">
                <item xsi:type="ns1:kategoria_drzewo">
                    <id xsi:type="xsd:int">382</id>
                    <nazwa xsi:type="xsd:string">Dom</nazwa>
                    <dane xsi:type="xsd:string">0</dane>
                    <id_rodzic xsi:type="xsd:int">1</id_rodzic>
                    <poziom xsi:type="xsd:int">0</poziom>
                    <id_prasa xsi:type="xsd:int">2</id_prasa>
                </item>
                <item xsi:type="ns1:kategoria_drzewo">
                    <id xsi:type="xsd:int">8251</id>
                    <nazwa xsi:type="xsd:string">Pokoje</nazwa>
                    <dane xsi:type="xsd:string"/>
                    <id_rodzic xsi:type="xsd:int">382</id_rodzic>
                    <poziom xsi:type="xsd:int">1</poziom>
                    <id_prasa xsi:type="xsd:int">0</id_prasa>
                </item>
            </drzewo_kategorii>
        </ns1:pobierz_kategorieResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

That is the request:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q1="http://soaptest.webapi-beta.gratka.pl/dom.html">
    <s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <q1:pobierz_kategorie>
            <sesja xsi:type="xsd:string">ad9e730460e334b916c95533c8da320003ac7e14</sesja>
            <id_kategoria xsi:type="xsd:int">382</id_kategoria>
        </q1:pobierz_kategorie>
    </s:Body>
</s:Envelope>

I've retrieved that WSDL and the response message name does not match what you have above. Where you have pobierz_kategorieResponse in the wsdl, it is pobierz_kategorie_wyjscie in the WSDL definition.

Message ...

  <message name="pobierz_kategorie_wyjscie">
    <part name="drzewo_kategorii" type="tns:drzewo_kategorii"/>
  </message>

Operation ...

<operation name="pobierz_kategorie">
  <input message="tns:pobierz_kategorie_wejscie"/>
  <output message="tns:pobierz_kategorie_wyjscie"/>
</operation>

Maybe you need to regenerate your service reference or point it at a different endpoint.

EDIT

You may have to customize your reference.cs file (your generated WCF client code) to handle the soap array. I haven't done this myself but there is an SO article about it:-
Why won't .NET deserialize my primitive array from a web service?
I'm not 100% sure if this is the same issue as what you are having. It looks like you need to tell WCF explicitly - for this element, this is how you de-serialize the array. Sorry I can't be of more help.

EDIT #2
There is a mismatch between the wsdl published to you 'soaptest' and the actual implementation. Note the namespaces. Or, you've generated your code of a test wsdl endpoint and pointed it at a prod endpoint.See the namespaces below.
Your request's namespaces looked like this:-

But the response's namespaces looked like this:-

That ain't gonna work!

Try generating your WCF client off

instead of off

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM