带输入参数的Yii soap web服务

时间:2014-06-27 10:28:25

标签: php web-services soap yii

我需要在使用Yii框架创建的soap webservice的构造函数输入中传递一个特殊的唯一键(string)。 这是我尝试的例子:

class SoapController extends Controller
{
private $uniqueKey;
public function __construct()
{
    $this->uniqueKey = $_GET['uniquekey'];
}

public function actions()
{
        return array(
                'service'=>array(
                        'class'=>'CWebServiceAction',
                ),
        );
}

/*
 * @return string result
 * @soap
 */
public function actionDemo()
{
    if(isset($this->uniqueKey))
        return $this->uniqueKey;
    else
        return 'key not set';
}
}

wsdl网址是:    ../index.php/soap/service?uniquekey=sss 这会在浏览器中显示wsdl数据。 但是,当我调用演示动作方法(例如使用visual studio)时,我得到了“请求失败,HTTP状态为404:未找到”。'

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message,WebResponse response,Stream responseStream,Boolean asyncCall)    在System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object []参数)    ...

在添加'?uniquekey = sss'之前,网络服务工作正常。一部分。

是否有另一种方法可以将$ uniqueKey作为__construct方法的参数传递,或者我是否需要自定义actions()方法? 拜托,我感谢任何建议。

1 个答案:

答案 0 :(得分:0)

您可以直接将uniquekey作为$ _GET参数发送到函数:

的index.php R = SoapController /显示&安培;唯一键= the_unique_key

Yii Controller:

class SoapController extends Controller
{
    public function actionShow($uniquekey)
    {
        //SOAP connect

        $this->render('show',array(
            'soap_data'=>$soap_data,
        ));
    }
}

PHP SOAP示例:

$options = array(
    'exceptions'=>true,
    'trace'=>1,
);

$client = new SoapClient("https://s7sps3apissl.scene7.com/scene7/webservice/IpsApi-2012-02-14.wsdl",$options);

$ns = 'http://www.scene7.com/IpsApi/xsd';

$auth = (object)array(
    'ns2:user' => 'xXx',
    'ns2:password' => 'xXx'
);

$header = new SoapHeader($ns, "authHeader", $auth, false);

$client->__setSoapHeaders(array($header));

//get company handle
$client->getCompanyInfo(array('companyName' => 'xXx'));

//extract company handle
preg_match('~<companyHandle>(.*?)</companyHandle>~s',$client->__getLastResponse(),$companyHandleMatch);

echo $companyHandleMatch[1];
相关问题