[英]Yii soap webservice with input parameter
我需要在使用Yii框架進行的soap webservice的構造函數輸入中傳遞一個特殊的唯一鍵(字符串)。 這是我嘗試過的示例:
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:找不到”。
在System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object [] parameters)處的System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage消息,WebResponse響應,流responseStream,布爾asyncCall)...
在添加'?uniquekey = sss'部分之前,該Web服務可以正常工作。
還有另一種方法可以將$ uniqueKey作為__construct方法的參數傳遞,或者我是否需要自定義actions()方法? 請,我感謝任何建議。
您可以直接將uniquekey作為$ _GET參數發送給函數:
index.php?r = SoapController / Show&uniquekey = the_unique_key
Yii控制器:
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.