logo       

Re: addComplexType problems with an associative array: msg#00111

php.nusoap.general

Subject: Re: addComplexType problems with an associative array

Here's the schema for Apache SOAP types:

<schema xmlns="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://xml.apache.org/xml-soap";
elementFormDefault="unqualified"
attributeFormDefault="unqualified">

<complexType name="Vector">
<sequence>
<element name="item" minOccurs="0" maxOccurs="unbounded" nillable="true" />
</sequence>
</complexType>

<complexType name="Map">
<sequence>
<element name="item" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="key" minOccurs="1" maxOccurs="1" />
<element name="value" minOccurs="1" maxOccurs="1" nillable="true" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>

</schema>

To use this, you might want to use a standalone WSDL file, rather than creating
WSDL programmatically, so that you can just paste this schema into the file.

Scott Nichol

Do not send e-mail directly to this e-mail address,
because it is filtered to accept only mail from
specific mail lists.
----- Original Message -----
From: "Mario" <mario@xxxxxx>
To: "Scott Nichol" <snicholnews@xxxxxxxxxxxxxxx>
Sent: Wednesday, April 27, 2005 2:40 PM
Subject: Re: [Nusoap-general] addComplexType problems with an associative array


> Hi Scott,
>
> thank you.
>
> But what can I do when I don't know how much key/value pairs my return
> array has?
>
> Regards,
> Mario
>
> Scott Nichol schrieb:
> > A PHP associative array corresponds to an XSD complexType, where the names
> > of the keys of the associative array are the names of the elements of the
> > complexType.
> >
> > The array created in
> >
> > array("ret_code"=>"200","ret_message"="User Okay.")
> >
> > corresponds to an XSD complexType like
> >
> > <complexType name="CheckUserReturn">
> > <all>
> > <element name="ret_code" type="xsd:string"/>
> > <element name="ret_message" type="xsd:string"/>
> > </all>
> > </complexType>
> >
> > which you can define in NuSOAP with
> >
> > $server->wsdl->addComplexType(
> > 'CheckUserReturn',
> > 'complexType',
> > 'struct',
> > 'all',
> > '',
> > array(
> > 'ret_code' => array('name'=>'ret_code','type'=>'xsd:string'),
> > 'ret_message' => array('name'=>'ret_message','type'=>'xsd:string')
> > )
> > );
> >
> > Scott Nichol
> >
> > Do not send e-mail directly to this e-mail address,
> > because it is filtered to accept only mail from
> > specific mail lists.
> > ----- Original Message -----
> > From: "Mario" <mario@xxxxxx>
> > To: <nusoap-general@xxxxxxxxxxxxxxxxxxxxx>
> > Sent: Wednesday, April 27, 2005 1:39 PM
> > Subject: [Nusoap-general] addComplexType problems with an associative array
> >
> >
> >
> >>Hello,
> >>
> >>I have a problem creating my WSDL file since days.
> >>I searched at Google and this mailing list archive but could'nt solve my
> >>problem.
> >>
> >>The problem is that I don't know how to send an associative array as the
> >>response to the client.
> >>
> >>This is my server:
> >>
> >>/*----------------------------------------------------------------------*/
> >>
> >>$server = new soap_server();
> >>
> >>$server->configureWSDL('Nameserver', $NAMESPACE);
> >>$server->wsdl->schemaTargetNamespace = $NAMESPACE;
> >>
> >>$server->wsdl->addComplexType(
> >>'ArrayOf_xsd_string',
> >>'complexType',
> >>'array',
> >>'',
> >>'SOAP-ENC:Array',
> >>array(),
> >>array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]')),'xsd:string'
> >>);
> >>
> >>function CheckUser($userid,$password,$userdata) {
> >>// some checks here
> >>return array("ret_code"=>"200","ret_message"="User Okay.");
> >>}
> >>
> >>$server->register('CheckUser', // method name
> >>array( 'userid'=>'xsd:int',
> >>'password'=>'xsd:string',
> >>'userdata'=>'tns:ArrayOf_xsd_string'
> >>), // input parameters
> >>array('return' => 'tns:ArrayOf_xsd_string'), // output parameters
> >>$NAMESPACE, // namespace
> >>'', // soapaction
> >>'rpc', // style
> >>'encoded', // use
> >>'Checks the nameserver configuration for a domain name' // documentation
> >>);
> >>
> >>// Use the request to (try to) invoke the service
> >>$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
> >>$server->service($HTTP_RAW_POST_DATA);
> >>
> >>/*----------------------------------------------------------------------*/
> >>
> >>This is my client:
> >>
> >>/*----------------------------------------------------------------------*/
> >>
> >>$client = new soapclient('http://myserver/server.php?wsdl', true);
> >>
> >>$result = $client->call('CheckUser',
> >>array( 'userid' => 123,
> >>'password' => "secret",
> >>'userdata' => array("Key1"=>"Value1","Key2"=>"Value2")
> >>)
> >>);
> >>
> >>print_r($result);
> >>
> >>/*----------------------------------------------------------------------*/
> >>
> >>The result currently looks like:
> >>
> >>Array
> >>(
> >> [0] => 200
> >> [1] => User Okay.
> >>)
> >>
> >>But I need it like this:
> >>
> >>Array
> >>(
> >> [ret_code] => 200
> >> [ret_message] => User Okay.
> >>)
> >>
> >>May I use "apachesoap:Map" for this? I found this in the nusoap class
> >>source code. But is there some documentation for this?
> >>
> >>What changes are needed to let asociative arrays work with WSDL?
> >>
> >>Thanks a lot and best regards,
> >>
> >>Mario
> >>
> >>
> >>-------------------------------------------------------
> >>SF.Net email is sponsored by: Tell us your software development plans!
> >>Take this survey and enter to win a one-year sub to SourceForge.net
> >>Plus IDC's 2005 look-ahead and a copy of this survey
> >>Click here to start! http://www.idcswdc.com/cgi-bin/survey?id=105hix
> >>_______________________________________________
> >>Nusoap-general mailing list
> >>Nusoap-general@xxxxxxxxxxxxxxxxxxxxx
> >>https://lists.sourceforge.net/lists/listinfo/nusoap-general
> >>
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net email is sponsored by: Tell us your software development plans!
> > Take this survey and enter to win a one-year sub to SourceForge.net
> > Plus IDC's 2005 look-ahead and a copy of this survey
> > Click here to start! http://www.idcswdc.com/cgi-bin/survey?id5hix
> > _______________________________________________
> > Nusoap-general mailing list
> > Nusoap-general@xxxxxxxxxxxxxxxxxxxxx
> > https://lists.sourceforge.net/lists/listinfo/nusoap-general
>


-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start! http://www.idcswdc.com/cgi-bin/survey?id5hix


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise