Home> PHP Framework> Laravel> body text

Code example of soapServer supporting wsdl under laravel framework

不言
Release: 2018-10-26 16:34:26
forward
5600 people have browsed it

本篇文章给大家带来的内容是关于laravel中soapServer支持wsdl的代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

$server = new \SoapServer(null, ['uri' => 'noganluonguri']); $server->setObject(new NganluongServer()); ob_start(); $server->handle(); return ob_get_clean();
Copy after login

上边这段代码是无wsdl模式下的,但是这次是对接第三方的服务,需要我们这边去定义soap webservice,第三方来调用,第三方定义的是wsdl模式的,所以今天研究了下。

laravel代码示例(其它框架类似思考方式):

  • 主要逻辑代码 - SoapService.php


        
Copy after login
  • 创建路由

$api->any('soapUrl', 'SoapCallbackController@soapFun');
Copy after login
  • 路由主要实现方法-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服务创建异常'); } } }
Copy after login
  • 生成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" . '\ngetName() . "Response\" />\n\n"; $bindingWSDL.= '\n" . '\nservice_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n\n\nservice_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\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"; } } ?>
Copy after login
  • webservice测试

getSum(10, 24); echo $soap->__soapCall('getSum',array(10,24));
Copy after login

The above is the detailed content of Code example of soapServer supporting wsdl under laravel framework. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!