Soap Ws And Param Filter

Hi!

on a SOAP web service, when I set this filter (to check a API key) :





protected function preFilter($filterChain)

{

	if ('testApiKey'

			!== Yii::app()->request->getParam('apiKey')) // the 'getParam()' here messes it all

		return false;

	return true;

}



Here is my test script :




<?php

$client=new SoapClient('https://myapp.local/mycontroller/service?apiKey=testApiKey', array(

  'soap_version' => SOAP_1_2, // or try SOAP_1_1

  'cache_wsdl' =>  WSDL_CACHE_NONE, // WSDL_CACHE_BOTH in production

  'trace' => 1,

));


var_dump($client->__getFunctions());


var_dump($client->foo('bar'));




Without the filter, I get :




array

  0 => string 'String foo(String $bar)' (length=24)


array

  0 => string 'bar' (length=3)



which is correct.

With my filter ON, I get :




array

  0 => string 'String foo(String $bar)' (length=24)


null




Howcome??

Thanks for your kind and much appreciated help!

SOAP does not support attributes like this.

What you are doing is you add a GET attribute to the WSDL url, not the method call. So it’s not there when you test for it in preFilter.

You need to add this attribute to every method you want to call through SOAP or use headers in SOAP client. Headers aren’t supported in the WSDL generator shipped with Yii, I’ve built my own and it currently awaits as a pull request.

Hi!

With this test script :




$client=new SoapClient('http://myapp.local/mycontroller/service/testApiKey', array(

  'soap_version' => SOAP_1_2, // or try SOAP_1_1

  'cache_wsdl' =>  WSDL_CACHE_NONE, // WSDL_CACHE_BOTH in production

  'trace' => 1,

  'exceptions' => true,

  'features' => SOAP_SINGLE_ELEMENT_ARRAYS,

));


var_dump($client->foo('bar'));



Wireshark shows me 3 HTTP sent requests :




107	2.134154	127.0.0.1	127.0.0.1	HTTP	70	GET /mycontroller/service/testApiKey HTTP/1.1 

126	2.154847	127.0.0.1	127.0.0.1	HTTP/XML	851	POST /mycontroller/service?ws=1 HTTP/1.1 

143	2.160741	127.0.0.1	127.0.0.1	HTTP	70	GET /mycontroller/service HTTP/1.1 



Tell me if I’m wrong :

  • the first one stands for the client instantiation and the WSDL Get

  • the second one is the call of the method

  • WTF is the last one ???

My idea was to check the API key only when Yii::app()-&gt;request-&gt;getParam('ws') is null (c.f. http://www.yiiframework.com/doc/api/1.1/CWebServiceAction#serviceVar-detail), but this last third request screws it all up (it has neither ‘ws’, nor ‘apiKey’ params)!

Please help!

Cheers!

I don’t know what’s calling that, maybe inspecting the HTTP headers would help.

If you want to do some filtering only for SOAP method calls use the beforeWebMethod and afterWebMethod methods. They are used when you controller implements the IWebServiceProvider interface.