gpt4 book ai didi

php - 如何在 Yii 中制作 Web 服务 SOAP 1.2

转载 作者:行者123 更新时间:2023-12-04 18:23:11 26 4
gpt4 key购买 nike

问题:

我不知道 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:
这是decesion,你需要有
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:
yii 硬编码soap1.1 如果你不提供你自己的wsdl(你可以通过$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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com