Webservice Generation + Yii


(nikolas) #1

I m trying to make a soal service and i face an issue with my wsdl

In my controller i have

public function actions()
{
    return array_merge(parent::actions(), array(
        'mapProcess' =>array(
            'class'=>'CWebServiceAction',
            'serviceOptions' =>
                array('generatorConfig' => 
                        array(
                            'class' => 'CWsdlGenerator',
                            'bindingStyle' => 'lieteral'))
        ),
    ));
}

/**
 * @param str/string the type of the map process
 * @return string[] the ouput of the proceedure
 * @soap
 */
public function actionMappings(){
    $response = [];
    $listofCategories = ["option1",
                        "option2",
                        "option3",
                        "option4",
                        "option5"];
    foreach($listofCategories as $singleCategory){
        $response[$singleCategory] = ($someCondition)?'Success':'Failure';
    }
    return ['actionMappingsResult' => $response];
}

the out come after calling the soap service is

  <ns1:actionMappingsResponse xsi:type="ns1:RefreshMappingsResponse">
     <actionMappingsResult SOAP-ENC:arrayType="xsd:string[15]" xsi:type="ns1:stringArray">
        <item xsi:type="xsd:string">Success</item>
        <item xsi:type="xsd:string">Success</item>
        <item xsi:type="xsd:string">Success</item>
        <item xsi:type="xsd:string">Success</item>
        <item xsi:type="xsd:string">Success</item>
     </actionMappingsResult>
  </ns1:actionMappingsResponse>

However the desired result would be

  <ns1:actionMappingsResponse xsi:type="ns1:RefreshMappingsResponse">
     <actionMappingsResult SOAP-ENC:arrayType="xsd:string[15]" xsi:type="ns1:stringArray">
        <option1 xsi:type="xsd:string">Success</option1>
        <option2 xsi:type="xsd:string">Success</option2>
        <option3 xsi:type="xsd:string">Success</option3>
        <option4 xsi:type="xsd:string">Success</option4>
        <option5 xsi:type="xsd:string">Success</option5>
     </actionMappingsResult>
  </ns1:actionMappingsResponse>

Is something wrong with my definitions? Is is possible what i am trying to do?


(nikolas) #2

Hi, i figured out what was going wrong, i guess it was pretty obvious that my array was created at runtime so it was not possible to be described at wsdl.
I followed instructions found over here https://www.yiiframework.com/doc/api/1.1/CWsdlGenerator and created a class with corresponding classname and worked liked a charm.
Problem occured when i wanted to add another class in the same php file (classname) Yii, tried to spot the new class in its own filename and not in the specified classname. I used classmap with no luck.

Any suggestions please?


(nikolas) #3

I have the following php file named WebServicesResults.php in the models folder

<?php

class WebServicesResults {
    
    /**
      * @var string name of WebServicesResults
      * @soap
      */
    public $name;
    /**
      * @var string members of WebServicesResults
      * @soap
      */
    public $members;
    
    function __construct($listofCategories, $members)
    {
//        $this->wsMappings = new GeneralMappings($listofCategories);
        $this->members = $members;
    }
}

class Mappings {
    /**
    * @var string option1 of Mappings 
    * @soap
    */
    public $option1;
    /**
    * @var string option2 of Mappings 
    * @soap
    */
    public $option2;
    /**
    * @var string option3 of Mappings 
    * @soap
    */
    public $option3;
    /**
    * @var string option4 of Mappings 
    * @soap
    */
    public $option4;
            
    function __construct($listofCategories)
    {
        foreach($listofCategories as $singleCategory){
            $this->$singleCategory = (SOME_CONDITION)?'Success':'Failure';
        }
    }    
}

In my controller, if i use this action

/**
 * @param str/string the type of the uncache process
 * @return WebServicesResults\Mappings xsd:struct
 * @soap
 */
public function actionRefreshMappings(){
    $response = new Mappings(["option1",
                        "option2",
                        "option3",
                        "option4"]);
    return [__FUNCTION__ . 'Result' => $response];
}

i get error
Alias “WebServicesResults.Mappings” is invalid. Make sure it points to an existing directory or file

if i alter to

 * @return WebServicesResults\\Mappings xsd:struct

Then i don’t get the same error but, in the generated WSDL the operation points to WebServicesResults class and not Mappings class

<xsd:element name="actionMappingsResponse">
     <xsd:complexType>
          <xsd:sequence>
              <xsd:element name="actionMappingsResult" type="tns:WebServicesResults"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

also the Mappings structure is not generated into WSDL