经过 4 天的测试并在 Stack Overflow: Importing Yii Created Soap Server To Visual Studio中询问,结果如下:
问:为什么我的 Yii soap 服务器无法在 Visual Studio 中导入?
A: Yii 对 WSDL 使用 RPC 编码样式,而 Visual Studio 需要文档/文字。因此,您可以使用 Zend Framework 库来创建文档/文字编码的 Web 服务器。
新问题:经过数小时的测试,我发现在函数中返回数组会导致 Visual Studio 无法导入它的错误。
SOAP返回数组数据类型有什么替代方案,所以Visual Studio可以导入服务器的WSDL吗?
此外,我无法在 Yii 中实现文档/文字 Zend 框架创建的肥皂服务器的实际示例,所以我编写了我编写的代码,也许其他人可以参考:
./protected/components/soapTTS.php
<?php
class soapTTS {
/**
* @param int $CourseId
* @return array
*/
public function ListAllStudentsOnASelectiveCourse($CourseId) {
$out = helper::ListAllStudentsOnASelectiveCourse($CourseId);
return $out;
}
}
?>
* @return array
在上面导致问题。
./protected/controllers/SoapController.php
<?php
class SoapController extends Controller {
public function actionService() {
Yii::import('application.vendors.*');
Yii::setPathOfAlias('Zend', Yii::getPathOfAlias('application.vendors.Zend'));
if (isset($_GET['wsdl'])) {
$autodiscover = new Zend\Soap\AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence());
$autodiscover->setBindingStyle(array('style' => 'document'));
$autodiscover->setOperationBodyStyle(array('use' => 'literal'));
$autodiscover->setClass('soapTTS');
$autodiscover->setUri('http://localhost/millms/mws/soap/service');
header("Content-type: text/xml");
echo $autodiscover->toXML();
} else {
// pointing to the current file here
$soap = new Zend\Soap\Server("http://localhost/millms/mws/soap/service?wsdl");
$soap->setObject(new Zend\Soap\Server\DocumentLiteralWrapper(new soapTTS()));
$soap->handle();
}
}
}
?>