问题:
我不明白 Yii 如何期望我更改 SOAP 版本。我正在关注这个tutorial 。 Web 服务可以工作,但不是 SOAP 1.2
类(class):
<?php
class ABFolioController extends CController
{
public function actions()
{
return array(
'folio'=>array(
'class'=>'CWebServiceAction',
'serviceOptions'=>array('soapVersion'=>'1.2')
),
);
}
/**
* @param string folioId
* @param string cNumber
* @param string oDRS
* @param string dlr
* @param string feeAmount
* @param string transactionStatus
* @param string captureId
* @param datetime captureTimestamp
* @param string prefix
* @param string oDEFRS
* @return string the statement
* @soap
*/
public function sendFolio($folioId, $cNumber, $oDRS, $dlr,
$feeAmount, $transactionStatus, $captureId, $captureTimestamp,
$prefix, $oDEFRS)
{
//
$model = new Dlfolio();
$model->folioId = $folioId;
$model->cNumber = $cNumber;
$model->oDRS = $oDRS;
$model->dlr = $dlr;
$model->feeAmount = $feeAmount;
$model->transactionStatus = $transactionStatus;
$model->captureId = $captureId;
$model->captureTimestamp = $captureTimestamp;
$model->prefix = $prefix;
$model->oDEFRS = $oDEFRS;
$yesno = $model->save();
if ($yesno=TRUE)
{
//on success
return 'Record Saved';
}
else
{
//on failure
return $yesno;
}
}
}
最佳答案
当我将客户端设置为 v1.2 时,我总是从服务器接收 v1.2 响应,当我将客户端设置为 v1.1 时,我总是从服务器接收 v1.1 响应,也许它会自动检测客户端版本并用它覆盖服务器版本?
$client=new SoapClient('http://hys.local/ABFolio/folio',array('soap_version'=>SOAP_1_2,'trace'=>true));
var_dump($client);
echo $client->sendFolio();
echo $client->__getLastRequest();
echo $client->__getLastResponse();
响应为 1.2
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
1.1 为客户端默认设置
$client=new SoapClient('http://hys.local/ABFolio/folio',array('soap_version'=>SOAP_1_1,'trace'=>true));
响应为 1.1
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
EDIT:
让我们看看yii的内部
framework\web\services\CWebService.php
/**
* @return array options for creating SoapServer instance
* @see http://www.php.net/manual/en/function.soap-soapserver-construct.php
*/
protected function getOptions()
{
$options=array();
if($this->soapVersion==='1.1')
$options['soap_version']=SOAP_1_1;
else if($this->soapVersion==='1.2')
$options['soap_version']=SOAP_1_2;
if($this->actor!==null)
$options['actor']=$this->actor;
$options['encoding']=$this->encoding;
foreach($this->classMap as $type=>$className)
{
$className=Yii::import($className,true);
if(is_int($type))
$type=$className;
$options['classmap'][$type]=$className;
}
return $options;
}
如果我检查此代码,我在您的代码中没有看到任何错误
EDIT:
好的,这个怎么样? framework\web\services\CWsdlGenerator.php
/*
* @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree
*/
private function addBindings($dom)
{
$binding=$dom->createElement('wsdl:binding');
$binding->setAttribute('name',$this->serviceName.'Binding');
$binding->setAttribute('type','tns:'.$this->serviceName.'PortType');
$soapBinding=$dom->createElement('soap:binding');
$soapBinding->setAttribute('style','rpc');
$soapBinding->setAttribute('transport','http://schemas.xmlsoap.org/soap/http');
$binding->appendChild($soapBinding);
$dom->documentElement->appendChild($binding);
foreach($this->_operations as $name=>$doc)
$binding->appendChild($this->createOperationElement($dom,$name));
}
正如我所见,传输是预定义的(您可以检查并将其替换为 12)
添加12后我的wsdl变成这样
<wsdl:binding name="ABFolioControllerBinding" type="tns:ABFolioControllerPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap12/http"/>
</wsdl:binding>
也许这是 yii 中的错误 - 然后报告它
但是从http://msdn.microsoft.com/en-us/library/ms995800.aspx
开始我检查的不是传输而是命名空间
SOAP versioning is based on XML namespaces. SOAP 1.1 is identified by the http://schemas.xmlsoap.org/soap/envelope/ namespace while SOAP 1.2 is identified by the http://www.w3.org/2002/12/soap-envelope namespace (although this will change when it becomes a Recommendation).
这就是为什么我认为一切都是正确的
EDIT:
这是你的决定
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
里面<definitions
在你的 xml 中除了
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
而不是这个:
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
你必须放置
<soap12:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
现在soapUI 检测到我的wsdl 为soap 1.2
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="urn:ABFolioControllerwsdl"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
name="ABFolioController"
targetNamespace="urn:ABFolioControllerwsdl">
<wsdl:portType name="ABFolioControllerPortType"/>
<wsdl:binding name="ABFolioControllerBinding" type="tns:ABFolioControllerPortType">
<soap12:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="ABFolioControllerService">
<wsdl:port name="ABFolioControllerPort" binding="tns:ABFolioControllerBinding">
<soap:address location="http://hys.local/uk/aBFolio/folio?ws=1"/>
</wsdl:port>
</wsdl:service>
</definitions>
您可以在 addBindings
中的 yii 中的相同文件中执行所有替换和buildDOM
功能
而且我认为这要困难得多,也就是说,如果你想同时支持soap和soap12绑定(bind),那么你必须同时拥有soap和soap12绑定(bind),但至少它已经被识别为soap12
EDIT:
如果您不提供自己的wsdl,则yii硬编码soap1.1(您可以通过$wsdlUrl提供它,就像在CWebService的run方法中一样)。这似乎是合法的 - 因为 php Soap 服务器中的默认 Soap 版本也是 1.1,如果您将版本更改为 1.2,则必须为 1.2 提供自己的 wsdl
关于php - 如何在 Yii 中制作 Web 服务 SOAP 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10247277/