Web Service Question

Hi all,

I’m fairly new to the Yii framework, but i must say it’s working out pretty well for me so far :wink:

I do have a specific situation I’m having trouble with…

I’ve extended the CDataProvider class for the sole purpose of changing the way my fetchData() function behaves (everything else is pretty much similar to the definition of the CActiveDataProvider class). Inside fetchData(), instead of the usual:


return CActiveRecord::model($this->modelClass)->findAll($criteria);

…I’m calling a web service to get my data, in the following way:


$this->soapClient->getData($this->modelClass);

Here’s the code for getData inside my ServiceController class:


	/**

	 * @param string the model

	 * @return array the data

	 * @soap

	 */

	public function getData($pModel)

	{

		$query = "SELECT * FROM {{" . $pModel . "}}";

		$command=Yii::app()->db->createCommand($query);

		return $command->query()->readAll();

        }



So far so good, but the problem begins as soon as I’m trying to pass additional arguments for my query criteria (so I can get sorting, pagination enabled, etc). If I change my function to:




	/**

	 * @param string the model

	 * @param CDbCriteria the criteria

	 * @return array the data

	 * @soap

	 */

	public function getData($pModel, $pCriteria)

	{

		$query = "SELECT * FROM {{" . $pModel . "}}";

		

		if (!empty($pCriteria->order))

		{

			$query .= " ORDER BY " . $pCriteria->order . "";

		}

		

		$query .= " LIMIT " . $pCriteria->limit . " OFFSET " . $pCriteria->offset . "";

		$command=Yii::app()->db->createCommand($query);

		return $command->query()->readAll();

	}



…I get the following error:

[b]Error 500

looks like we got no XML document[/b]

I realized that since I’m passing an object as one of my arguments, that it could be the reason for this, but I even tried passing my criteria parameters separately (like $pCriteria->order, $pCriteria->limit, $pCriteria->offset), and i still get the same error message. What could be causing this…

Thanks in advance

Regarding the "no XML document" error, check for syntax errors and correct class names (e.g. I experienced this message using a bad model class name). Do you get the WSDL if navigating your browser to the web service (controller/your_webservice_action)?

For passing a criteria object I think you may want to inherit (and use) your own DbCriteria class and add the following declarations to it




  /**

   * @var string

   * @soap

   */

  public $order;


  /**

   * @var integer

   * @soap

   */

  public $limit;


  /**

   * @var integer

   * @soap

   */

  public $offset;



/Tommy

thanks for you help Tommy. I finally got it to work. Also (and this might be interesting to others who are using web services), it helps to disable the wsdl cache (set soap.wsdl_cache_enabled=0). I noticed that with cache enabled, it would complain about newly added soap functions, claiming that ‘Function *** is not a valid method of this service’…