本篇文章给大家带来的内容是关于laravel中soapserver支持wsdl的代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
$server = new \SoapServer(null, ['uri' => 'noganluonguri']); $server->setObject(new NganluongServer()); ob_start(); $server->handle(); return ob_get_clean();
上边这段代码是无wsdl模式下的,但是这次是对接第三方的服务,需要我们这边去定义soap webservice,第三方来调用,第三方定义的是wsdl模式的,所以今天研究了下。
laravel代码示例(其它框架类似思考方式):
主要逻辑代码 - SoapService.php
创建路由
免费红色响应式多语言企业通用模板1.0.0下载该模板源码有公司简介、公司新闻、产品展示、客户案例、留言等企业官网常用页面功能。模板是响应式模板,支持多语言,完善的标签调用修改起来很方便。功能特点:1. 使用的框架采用HkCms开源内容管理系统v2.2.3版本、免费可以商用。2. 所需环境Apache/Nginx,PHP7.2 及以上 + MySQL 5.6 及以上。3. 安装教程: (1) 站点运行路径填写到public目录下。 (2) 浏览
$api->any('soapUrl', 'SoapCallbackController@soapFun');路由主要实现方法-wsdl不存在则创建,不需要手动创建,url:https:xxx/soapurl?wsdl
getWSDL());
fclose($file);
}
$server = new \SoapServer($storagePath . '/wsdl/' . $className . '.wsdl', array('soap_version' => SOAP_1_2));
$server->setClass($procClass);
$server->handle();
} catch (\Exception $e) {
Log::error('wsdl服务创建异常');
}
}
}生成wsdl类 - SoapDiscovery.php
class_name = $class_name;
$this->service_name = $service_name;
}
/**
* SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.
*
* @return string
* */
public function getWSDL() {
if (empty($this->service_name)) {
throw new Exception('No service name.');
}
$headerWSDL = "\n";
$headerWSDL.= "service_name\" targetNamespace=\"urn:$this->service_name\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"urn:$this->service_name\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n";
$headerWSDL.= " \n";
if (empty($this->class_name)) {
throw new Exception('No class name.');
}
$class = new ReflectionClass($this->class_name);
if (!$class->isInstantiable()) {
throw new Exception('Class is not instantiable.');
}
$methods = $class->getMethods();
$portTypeWSDL = '';
$bindingWSDL = '\n \n";
$serviceWSDL = '\n \nservice_name . 'Port" binding="tns:' . $this->service_name . "Binding\"> \n \n \n";
$messageWSDL = '';
foreach ($methods as $method) {
if ($method->isPublic() && !$method->isConstructor()) {
$portTypeWSDL.= '\n" . '\n \n";
$bindingWSDL.= '\n" . ' \nservice_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n\n\n \n";
$messageWSDL.= '\n";
$parameters = $method->getParameters();
foreach ($parameters as $parameter) {
$messageWSDL.= ' \n";
}
$messageWSDL.= " \n";
$messageWSDL.= '\n";
$messageWSDL.= ' \n";
$messageWSDL.= " \n";
}
}
$portTypeWSDL.= " \n";
$bindingWSDL.= "\n";
//return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ' ');
//生成wsdl文件,将上面的return注释
$fso = fopen($this->class_name . ".wsdl", "w");
fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ''));
}
/**
* SoapDiscovery::getDiscovery() Returns discovery of WSDL.
*
* @return string
* */
public function getDiscovery() {
return "\n\n \n ";
}
}
?>webservice测试
getSum(10, 24);
echo $soap->__soapCall('getSum',array(10,24));









