Page 1 of 1

passing an array of complex types from php web service to c#

Posted: Mon Apr 23, 2007 12:18 pm
by dninja
I have a php web service with a complex type defined. I can pass a single element of this type from server to client and I can also pass an array of this type in but I can't pass an array back out again. A snippit of the code is:

Code: Select all

function ArrayTester()
    {   
        $this->__dispatch_map['singleInSingleOut'] = array(
            "in" => array ("inp" => "{urn:ArrayTest}Test"),
            "out" => array ("outp" => "{urn:ArrayTest}Test")
        );  
        $this->__dispatch_map['arrayInSingleOut'] = array(
            "in" => array ("inp" => "{urn:ArrayTest}ArrayOfTests"),
            "out" => array ("outp" => "{urn:ArrayTest}Test")
        );  
        $this->__dispatch_map['singleInArrayOut'] = array(
            "in" => array ("inp" => "{urn:ArrayTest}Test"),
            "out" => array ("outp" => "{urn:ArrayTest}Test")
        );  
        $this->__dispatch_map['arrayInArrayOut'] = array(
            "in" => array ("inp" => "{urn:ArrayTest}ArrayOfTests"),
            "out" => array ("outp" => "{urn:ArrayTest}ArrayOfTests")
        );  
        $this->__typedef['ArrayOfTests'] = array(array('item'=>'{urn:ArrayTest}Test'));
        $this->__typedef['Test'] = array(
                                        "item" => 'string',
                                        "item2" => "string",
                                        "number" => "int",
                                        );  

    function arrayInArrayOut($inp) {
        $p = new Test();
        $p->set_item ("item1");
        $o = new Test();
        $o->set_item ("item2");
        $out = array ($o, $p);
        
        $h = fopen ("/tmp/web.log", "a+");
        fwrite ($h, print_r ($inp, true));
        fwrite ($h, print_r ($out, true));
        fclose ($h);
        
        return (array());
    }
    
    function singleInArrayOut ($inp) {
        $p = new Test();
        $p->set_item ("item1");
        $o = new Test();
        $o->set_item ("item2");
        $out = array ($o, $p);
        
        $h = fopen ("/tmp/web.log", "a+");
        fwrite ($h, print_r ($inp, true));
        fwrite ($h, print_r ($out, true));
        fclose ($h);
        return $out;
    }
    
    function singleInSingleOut ($inp) {
        $out = new Test();
        $out->set_item ("item1");
        
        $h = fopen ("/tmp/web.log", "a+");
        fwrite ($h, print_r ($inp, true));
        fwrite ($h, print_r ($out, true));
        fclose ($h);
        return $out;
    }
    
    function arrayInSingleOut ($inp) {
        $out = new Test();
        $out->set_item ("item1");
        
        $h = fopen ("/tmp/web.log", "a+");
        fwrite ($h, print_r ($inp, true));
        fwrite ($h, print_r ($out, true));
        fclose ($h);
        return $out;
    }
The ...SingleOut functions work ok but the ...ArrayOut functions fail. Visual studio puts an <undefined value> into the variable.

The namespaces seem to be ok or c# would completely fail.

Checking the log shows that everything seems to be of the right types.

On the arrayInArrayOut function, I've tried returning the input as the output (i.e. no alterations) and that failed.

I've see some things define sequences rather than arrays, as long as I get multiple of these types out I don't care how I do it.

Can anyone help or point me at some example code that does this? There are loads of simple type examples but very few complex type ones.

Posted: Mon Apr 23, 2007 12:22 pm
by Burrito
how are you trying to retrieve your array in c#? What kind of array are you using in c# (string dictionary, string array, int array etc)?

Posted: Mon Apr 23, 2007 12:39 pm
by dninja
Burrito wrote:how are you trying to retrieve your array in c#? What kind of array are you using in c# (string dictionary, string array, int array etc)?
The variable on the c# side is

Test[] tout = arrayOutSingleIn (tin);

Anything else and the compiler complains.

I've checked the stub created by visual studio and that is the right type.

Posted: Mon Apr 23, 2007 1:01 pm
by Burrito
how are you getting the array from php to c# though?

Posted: Mon Apr 23, 2007 1:20 pm
by volka
May we see the wsdl code of your webservice?

Posted: Wed Apr 25, 2007 3:32 am
by dninja
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[quote="volka"]May we see the wsdl code of your webservice?[/quote]

Here you go

[syntax="xml"]
<?xml version="1.0"?><definitions name="PathFinder" targetNamespace="urn:PathFinder" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:PathFinder" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types xmlns="http://schemas.xmlsoap.org/wsdl/">
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:PathFinder">
<complexType name="ArrayOfStrings">
<complexContent>
<restriction base="SOAP-ENC:Array">
<attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="xsd:string[]" />
</restriction>
</complexContent>
</complexType>
<complexType name="ArrayOfTests">
<complexContent>
<restriction base="SOAP-ENC:Array">
<attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:Test[]" />
</restriction>
</complexContent>
</complexType>
<complexType name="Test">
<all>
<element name="item" type="xsd:string" />
<element name="item2" type="xsd:string" />
<element name="number" type="xsd:int" />
</all>
</complexType>
</schema>
</types>
<message name="do_it3Request">
<part name="inp" type="tns:ArrayOfTests" />
</message>
<message name="do_it3Response">
<part name="outp" type="xsd:sequence" />
</message>
<message name="do_itRequest">
<part name="inp" type="tns:ArrayOfTests" />
</message>
<message name="do_itResponse">
<part name="outp" type="tns:Test" />
</message>
<message name="do_it2Request">
<part name="inp" type="tns:Test" />
</message>
<message name="do_it2Response">
<part name="outp" type="tns:Test" />
</message>
<message name="array_testRequest">
<part name="inp" type="tns:ArrayOfStrings" />
</message>
<message name="array_testResponse">
<part name="outp" type="tns:ArrayOfStrings" />
</message>
<portType name="PathFinderPort">
<operation name="do_it3">
<input message="tns:do_it3Request" />
<output message="tns:do_it3Response" />
</operation>
<operation name="do_it">
<input message="tns:do_itRequest" />
<output message="tns:do_itResponse" />
</operation>
<operation name="do_it2">
<input message="tns:do_it2Request" />
<output message="tns:do_it2Response" />
</operation>
<operation name="array_test">
<input message="tns:array_testRequest" />
<output message="tns:array_testResponse" />
</operation>
</portType>
<binding name="PathFinderBinding" type="tns:PathFinderPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="do_it3">
<soap:operation soapAction="http://schemas.xmlsoap.org/soap/envelope/#pathfinder#do_it3" />
<input>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="do_it">
<soap:operation soapAction="http://schemas.xmlsoap.org/soap/envelope/#pathfinder#do_it" />
<input>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="do_it2">
<soap:operation soapAction="http://schemas.xmlsoap.org/soap/envelope/#pathfinder#do_it2" />
<input>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="array_test">
<soap:operation soapAction="http://schemas.xmlsoap.org/soap/envelope/#pathfinder#array_test" />
<input>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="PathFinderService">
<documentation />
<port name="PathFinderPort" binding="tns:PathFinderBinding">
<soap:address location="http://hp.dev/example.php" />
</port>
</service>
</definitions>


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Apr 25, 2007 3:35 am
by dninja
Burrito wrote:how are you getting the array from php to c# though?
Not sure what you mean, I'm building an array in the php function then returning it with return.