views:

256

answers:

1

I'm trying to consume a soap feed using the PHP SoapClient and convert it to an array. It works great until I run into an object that is a complexType.

Then it returns...

[0] => stdClass Object

...instead of showing the multiple elements that are displayed when I access the SOAP feed otherwise.

I'm very new to SOAP, so any help is appreciated.

The relevant part of the WSDL looks like this...

<xs:complexType name="UserInfo"> 
            <xs:complexContent> 
                <xs:extension base="tns:UserBaseInfo"> 
                    <xs:sequence> 
                        <xs:element minOccurs="0" name="contact_name" type="xs:string"/> 
                        <xs:element minOccurs="0" name="group_name" type="xs:string"/> 
                        <xs:element name="active" type="xs:boolean"/> 
                        <xs:element name="validated" type="xs:boolean"/> 
                        <xs:element name="deleted" type="xs:boolean"/> 
                        <xs:element name="hidden" type="xs:boolean"/> 
                        <xs:element minOccurs="0" name="deleted_date" type="xs:dateTime"/> 
                        <xs:element minOccurs="0" name="pref_contact" type="xs:string"/> 
                        <xs:element minOccurs="0" name="last_login_date" type="xs:dateTime"/> 
                        <xs:element minOccurs="0" name="last_modify" type="xs:dateTime"/> 
                        <xs:element minOccurs="0" name="updated_by" type="xs:string"/> 
                        <xs:element name="no_mass_email" type="xs:boolean"/> 
                        <xs:element minOccurs="0" name="pref_bb_contact" type="xs:string"/> 
                        <xs:element minOccurs="0" name="pref_bb_image" type="xs:string"/> 
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="attribute_list" type="tns:UserAttInfo"/> 
                    </xs:sequence> 
                </xs:extension> 
            </xs:complexContent> 
        </xs:complexType> 

        <xs:complexType name="UserAttInfo"> 
            <xs:sequence> 
                <xs:element name="user_id" type="xs:string"/> 
                <xs:element name="att_id" type="xs:string"/> 
                <xs:element minOccurs="0" name="att_name" type="xs:string"/> 
                <xs:element minOccurs="0" name="att_type_id" type="xs:string"/> 
                <xs:element minOccurs="0" name="att_type_name" type="xs:string"/> 
                <xs:element minOccurs="0" name="att_data" type="xs:string"/> 
                <xs:element name="hidden" type="xs:boolean"/> 
                <xs:element minOccurs="0" name="last_modify" type="xs:dateTime"/> 
                <xs:element name="view_only" type="xs:boolean"/> 
                <xs:element name="editable" type="xs:boolean"/> 
            </xs:sequence> 
        </xs:complexType> 

I'm My PHP code looks like this...

$wsdl = new SoapClient('https://location.com/UserService?wsdl', array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));


    $data = $wsdl->$method($params);

    $result['gusername']            = $username;
    $result['password']             = $password;

    $result['user_id']              = $data->return->user_id;           // 8 digits integer <user_id>16977408</user_id>
    $result['group_id']             = $data->return->group_id;          // 6 digits integer
    $result['org_id']               = $data->return->org_id;            // 3 letter string
    $result['contact_name']         = $data->return->contact_name;      // string
    $result['active']               = $data->return->active;            // boolean
    $result['validated']            = $data->return->validated;         // boolean
    $result['deleted']              = $data->return->deleted;           // boolean
    $result['hidden']               = $data->return->hidden;            // boolean
    $result['last_login_date']      = $data->return->last_login_date;   // date string
    $result['last_modify']          = $data->return->last_modify;       // date string
    $result['updated_by']           = $data->return->updated_by;        // string
    $result['no_mass_email']        = $data->return->no_mass_email;     // boolean
    $result['pref_bb_contact']      = $data->return->pref_bb_contact;   // string
    $result['pref_bb_image']        = $data->return->pref_bb_image;     // string
    $result['attribute_list']       = $data->return->attribute_list; 

The resulting output looks like this...

    Array
(
    [gusername] => jsmith
    [password] => password
    [user_id] => 123456789
    [group_id] => 123456
    [org_id] => obs
    [contact_name] => John Smith
    [active] => 1
    [validated] => 1
    [deleted] => 
    [hidden] => 
    [last_login_date] => 2010-08-17T14:39:41Z
    [last_modify] => 2010-03-29T22:43:42Z
    [updated_by] => John Smith
    [no_mass_email] => 
    [pref_bb_contact] => 
    [pref_bb_image] => 
    [attribute_list] => Array
        (
            [0] => stdClass Object
                (
                )

        )

)

Here's what the raw xml output looks like...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
    -<soapenv:Body>
        -<authenticateUserResponse xmlns="http://ws.domain.com/xsd"&gt;
        -<return>
            -<user_id>12345679</user_id>
            -<group_id>100400</group_id>
            -<org_id>obs</org_id>
            -<contact_name>John Smith</contact_name>
            -<active>true</active>
            -<validated>true</validated>
            -<deleted>false</deleted>
            -<hidden>false</hidden>
            -<last_login_date>2010-08-17T14:39:41Z</last_login_date>
            -<last_modify>2010-03-29T22:43:42Z</last_modify>
            -<updated_by>John Smith</updated_by>
            -<no_mass_email>false</no_mass_email>
            -<pref_bb_contact></pref_bb_contact>
            -<pref_bb_image></pref_bb_image>
            -<attribute_list>
                -<UserAttInfo>
                    -<user_id>123456798</user_id>
                    -<att_id>406833</att_id>
                    -<att_name>Contact Name</att_name>
                    -<att_type_id>16</att_type_id>
                    -<att_type_name>Contact Center Greeting</att_type_name>
                    -<att_data>John Smith</att_data>
                    -<hidden>false</hidden>
                    -<last_modify>2009-11-11T22:13:13Z</last_modify>
                    -<view_only>false</view_only>
                    -<editable>true</editable>
                </UserAttInfo>
                -<UserAttInfo>
                    -<user_id>16977408</user_id>
                    -<att_id>406824</att_id>
                    -<att_name>Email</att_name>
                    -<att_type_id>1</att_type_id>
                    -<att_type_name>E-mail Address (Contact Center)</att_type_name>
                    -<att_data>[email protected]</att_data>
                    -<hidden>false</hidden>
                    -<last_modify>2009-11-11T22:13:13Z</last_modify>
                    -<view_only>false</view_only>
                    -<editable>true</editable>
                </UserAttInfo>
            </attribute_list>
        </return>
        </authenticateUserResponse>
    </soapenv:Body>
</soapenv:Envelope>
A: 

I'm getting closer, but still no dice...

I believe the solution is to use classmap to get everything working, but I'm still getting a lot of empty space.

     // authenticateUser
    class UserAttInfo  // extends stdClass
    {
        public $user_id;
        public $att_id;
        public $att_name;
        public $att_type_id;
        public $att_type_name;
        public $att_data;
        public $hidden;
        public $last_modify;
        public $view_only;
        public $editable;
    }

// Create the SOAP Client
    $wsdl_url = 'https://server.com/mc/services/UserService?wsdl';
    $classmap = array('UserAttInfo' => "UserAttInfo");
    $features = array( 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'classmap' => $classmap);
    $wsdl =     new SoapClient($wsdl_url, $features);


    // Call the SOAP Connection
    $method = 'authenticateUser';
    $params->org_id     = $org_id;
    $params->username   = $username;
    $params->password   = $password;
    $data = $wsdl->$method($params);
    print_r ($data);

Now I seem to be getting the format in there, but no data yet?

stdClass Object
(
    [return] => stdClass Object
        (
            [user_id] => 16977408
            [group_id] => 100400
            [org_id] => obs
            [contact_name] => John Smith
            [active] => 1
            [validated] => 1
            [deleted] => 
            [hidden] => 
            [last_login_date] => 2010-08-17T14:39:41Z
            [last_modify] => 2010-03-29T22:43:42Z
            [updated_by] => John Smith
            [no_mass_email] => 
            [pref_bb_contact] => 
            [pref_bb_image] => 
            [attribute_list] => Array
                (
                    [0] => UserAttInfo Object
                        (
                            [user_id] => 
                            [att_id] => 
                            [att_name] => 
                            [att_type_id] => 
                            [att_type_name] => 
                            [att_data] => 
                            [hidden] => 
                            [last_modify] => 
                            [view_only] => 
                            [editable] => 
                        )

                )

        )

)

Anybody know more about this?

Dan PEterson