views:

920

answers:

1

I am receiving the following error when calling a web service method.

Cannot assign object of type System.Xml.XmlNode[] to an object of type System.String.

The web service is a PHP service. I created my proxy class using wsdl.exe from the wsdl document defined here - http://webservice.intelecast.com.au/traffic/PublicSoap/server.php?wsdl

Below is the proxy client method I am calling.

[System.Web.Services.Protocols.SoapRpcMethodAttribute("http://webservice.intelecast.com.au/traffic/PublicSoap/server.php#getAllTraffic", RequestNamespace="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php", ResponseNamespace="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php")]
 [return: System.Xml.Serialization.SoapElementAttribute("return")]
 public TmcInfo[] getAllTmcTraffic(string[] States, int[] EventCodes) {
     object[] results = this.Invoke("getAllTmcTraffic", new object[] { //Error here
                 States,
                 EventCodes});

It appear the proxy class is failing to deal with the complex types/arrays defined in the wsdl...I am unsure now how to proceed can't find a solution on the web anywhere.

Below is the SOAP response i am receiving. This all appears valid.

<?xml version="1.0" encoding="iso-8859-1"?>
<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:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:tns="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php"&gt;
    <SOAP-ENV:Body>
        <ns1:getAllTrafficResponse 
            xmlns:ns1="http://webservice.intelecast.com.au/traffic/PublicSoap/server.php"&gt;
            <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:TrafficInfo[2]">
                <item xsi:type="tns:TrafficInfo">
                    <id xsi:type="xsd:string">1245632068110</id>
                    <entryDate xsi:type="xsd:datetime">22/06/2009 10:54:28</entryDate>
                    <direction xsi:type="xsd:int">0</direction>
                    <extent xsi:type="xsd:int">1</extent>
                    <locationCode xsi:type="xsd:int">31593</locationCode>
                    <countryCode xsi:type="xsd:int">4</countryCode>
                    <ltn xsi:type="xsd:int">56</ltn>
                    <diversionAdvice xsi:type="xsd:int">0</diversionAdvice>
                    <slAdvice xsi:type="xsd:int">0</slAdvice>
                    <quantifier xsi:type="xsd:int">0</quantifier>
                    <suppInfoCode xsi:type="xsd:int">0</suppInfoCode>
                    <addEvent xsi:type="xsd:int">0</addEvent>
                    <detDivAdvice xsi:type="xsd:int">0</detDivAdvice>
                    <destinations xsi:type="xsd:int">0</destinations>
                    <clSourceProblem xsi:type="xsd:int">0</clSourceProblem>
                    <eventCode xsi:type="xsd:int">802</eventCode>
                    <timeInfo xsi:type="tns:TimeInfo">
                        <start xsi:type="xsd:string">21/06/2009 14:00:00</start>
                        <finish xsi:type="xsd:string">05/11/2009 14:00:00</finish>
                        <timeZone xsi:type="xsd:string">Australia/Brisbane</timeZone>
                    </timeInfo>
                    <location xsi:type="tns:Point">
                        <lat xsi:type="xsd:float">-27.3112692120521</lat>
                        <lon xsi:type="xsd:float">153.029100894928</lon>
                    </location>
                    <additionalStreetInfo 
                      xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:AdditionalStreetInfo[1]">
                        <item xsi:type="tns:AdditionalStreetInfo">
                            <street xsi:type="xsd:string">Bracken Ridge Rd</street>
                            <type xsi:type="xsd:string">CROSS</type>
                        </item>
                    </additionalStreetInfo>
                    <address xsi:type="tns:Address">
                        <streetNumber xsi:type="xsd:string"/>
                        <streetName xsi:type="xsd:string">Bracken Ridge Rd</streetName>
                        <suburb xsi:type="xsd:string">Bracken Ridge</suburb>
                        <state xsi:type="xsd:string">QLD</state>
                    </address>
                </item>
                <item xsi:type="tns:TrafficInfo">
                    <id xsi:type="xsd:string">1245632111995</id>
                    <entryDate xsi:type="xsd:datetime">22/06/2009 10:55:11</entryDate>
                    <direction xsi:type="xsd:int">1</direction>
                    <extent xsi:type="xsd:int">1</extent>
                    <locationCode xsi:type="xsd:int">31592</locationCode>
                    <countryCode xsi:type="xsd:int">4</countryCode>
                    <ltn xsi:type="xsd:int">56</ltn>
                    <diversionAdvice xsi:type="xsd:int">0</diversionAdvice>
                    <slAdvice xsi:type="xsd:int">0</slAdvice>
                    <quantifier xsi:type="xsd:int">0</quantifier>
                    <suppInfoCode xsi:type="xsd:int">0</suppInfoCode>
                    <addEvent xsi:type="xsd:int">0</addEvent>
                    <detDivAdvice xsi:type="xsd:int">0</detDivAdvice>
                    <destinations xsi:type="xsd:int">0</destinations>
                    <clSourceProblem xsi:type="xsd:int">0</clSourceProblem>
                    <eventCode xsi:type="xsd:int">802</eventCode>
                    <timeInfo xsi:type="tns:TimeInfo">
                        <start xsi:type="xsd:string">21/06/2009 14:00:00</start>
                        <finish xsi:type="xsd:string">05/11/2009 14:00:00</finish>
                        <timeZone xsi:type="xsd:string">Australia/Brisbane</timeZone>
                    </timeInfo>
                    <location xsi:type="tns:Point">
                        <lat xsi:type="xsd:float">-27.3125370752656</lat>
                        <lon xsi:type="xsd:float">153.042898178101</lon>
                    </location>
                    <additionalStreetInfo 
                       xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:AdditionalStreetInfo[1]">
                        <item xsi:type="tns:AdditionalStreetInfo">
                            <street xsi:type="xsd:string">Bracken Ridge Rd</street>
                            <type xsi:type="xsd:string">CROSS</type>
                        </item>
                    </additionalStreetInfo>
                    <address xsi:type="tns:Address">
                        <streetNumber xsi:type="xsd:string"/>
                        <streetName xsi:type="xsd:string">Bracken Ridge Rd</streetName>
                        <suburb xsi:type="xsd:string">Bracken Ridge</suburb>
                        <state xsi:type="xsd:string">QLD</state>
                    </address>
                </item>
            </return>
        </ns1:getAllTrafficResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
A: 

Is it a bug in wsdl.exe? I have a few unpleasant encounters with wsdl.exe. Here are the problems outlined in my post:

The first issue it fails to handle sequence with complex element. You would think that in today's webservice environment, a sequence of complex elements is a norm. But apparently Microsoft doesn't think so, and this results in inability of wsdl.exe to handle a sequence of complex elements.

What if you insist on using wsdl.exe to generate proxy class for element with a sequence of complex types? You will get a cryptic exception: unable to import binding * from namespace * - unable to import operation * - the datatype * is missing The second bug wsdl has is that it is not permissible to have two web methods that have the same return signature. Yes, if one method returns a type of ComplexType, the other methods must have a different return type. Failing to do so will result in an System.InvalidOperationException: The XML element * from namespace * references a references a method and a type exception.

Note that in both cases the messages are cryptic. You won't actually know what's going on behind the hood. And this is the most frustrating of all. You don't know whether you fail because the tool is lousy, or because you are not doing things right.

Maybe you can refer to this post for an alternative of wsdl.exe.

Ngu Soon Hui
I think it may be similar to the first issue. It fails to handle certain complex elements. It could be more related to the xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType type data in the SOAP envelope. I'm not using WCF, that other post didn't really help.
James Hull
If this were the case then I afraid that you couldn't use wsdl.exe because MS doesn't plan to fix that bug
Ngu Soon Hui
I've tried to implement this proxy consumer using WCF and I get the same error message. Interesting...
James Hull