Yii Web Services And Mtom

Hi - I have been looking how to return a binary file on a web service and using the Yii built in functionality i don’t see an option to activate a MTOM data type base64binary, the framework only maps simple types like:

str/string: maps to xsd:string;

int/integer: maps to xsd:int;

float/double: maps to xsd:float;

bool/boolean: maps to xsd:boolean;

date: maps to xsd:date;

time: maps to xsd:time;

datetime: maps to xsd:dateTime;

array: maps to xsd:string;

object: maps to xsd:struct;

mixed: maps to xsd:anyType.

i have been trying to return a string data type with base64 encoded string but it doesn’t works, do someone knows how to do this?

My code:


 * @param int id document id

 * @return string base64 encoded document

 * @soap


 public function getDocument($id) {

    $model=Document::model()->findByPk((int) $id);


            throw new CHttpException(404,'The requested page does not exist.');

    $file = $model->file_pdf;       

    if($file != null) {       

         $binfile = $this->getFile($file);


    return $binfile;


Im getting this as result:

<SOAP-ENV:Envelope …>



     &lt;return xsi:type=&quot;xsd:string&quot;&gt;&lt;/return&gt;




----------- UPDATE -------------------

Finally i got the binary data to the web service but not in base64 data type

<return xsi:type="xsd:string">JVBERi0xLjQKJeLjz9MKMSAwIG…

It stills as string, i need to be base64


So now you have to decode this base64 encryption. If your client is on php side all you have to do is use function base64_decode.

Thank you for your response mrk, but what i need is to use MTOM funcionality, it is supposed more efficient to transmit files embedded on webservices than base64 strings because the size of the file is increased 33%, in my code im getting this

This datatype it’s supposed to be xsi:type=“base64Binary” and it appears as xsi:type=“xsd:string”

<return xsi:type="xsd:string">JVBERi0xLjQKJeLjz9MKMSAwIG…

Lookig deep on yii documentation it’s mentioned that it’s possible to use that data type but i don’t find how to do that…



I had a quick glance at Yii WSDL generation codes. What I found is that all this config can unfortunately be used with CWsdlGenerator because even if you pass some additional config to it, it’s clearing all private properies (that can be customized) before wsdl generation.

However I don’t think you have to change anything in this config.

You have your method that returns this encoded base64, it’s probably in some kind of facade etc, and to integrate it with soap it have some annotations added.

Can you show signature of this method, and probably some random other one (to compare)? Because I guess, all you’ll have to do to solve this problem will be to set proper type in annotation.

To use xsd:base64Binary, you must extends CWsdlGenerator. Create constructor and add new typeMap. Like this :

public function __construct()


self::$typeMap[‘base64Binary’] = ‘xsd:base64Binary’;


In your controller class that representing web service action, add web service parameter like this :

//as describe in yii definitive guide 8.7.2

public function actions()


return array(











In your doc comment data type declaration, now you can use base64Binary as data type.