在下新手,正在用Laravel
框架和xampp
搭建一个后台管理系统。因为有需要做webservice接口功能,使用到了php中的soap,然而开发过程中出现了Function doesn't exist
的问题,卡了好久,因此前来求助。具体如下:
有这么两个php文件:
①client.php,作为soap客户端
路径:C:xampphtdocsmy_projectappServicesclient.php
<code class="php"><?php try { $client = new SoapClient(null, array('location' => "http://localhost/my_project/app/Services/server.php", 'uri' => "http://localhost/", 'encoding' => 'UTF-8')); echo $client->hello(); } catch (SoapFault $fault) { echo "Error: ", $fault->faultcode, ", String: ", $fault->getMessage(); }</code>
②server.php,作为soap服务端
路径:C:xampphtdocsmy_projectappServicesserver.php
<code><?php namespace App\Services; use App\User; // User是Laravel中的model,在C:\xampp\htdocs\my_project\app下 try { $soap = new \SoapServer(null, array('uri' => "localhost")); $soap->addFunction('hello'); $soap->handle(); }catch (\SoapFault $fault) { echo "Error: ", $fault->faultcode, ", String: ", $fault->faultstring; } function hello() { $model = new User; return "hello"; }</code>
因为有需要用到模板,因此在server.php
中使用了namespace
,并把User
类用use
的方式引用进来。但是这样一来server.php
中的SoapServer
和SoapFault
前面就要加上斜杠,变成SoapServer
和SoapFault
最后在浏览器中运行C:xampphtdocsmy_projectappServicesclient.php
时却出现了Error: SOAP-ENV:Server, String: Function 'hello' doesn't exist
错误提示,百度谷歌一直未果,希望有经验的前辈能指点一下,不胜感激!
在下新手,正在用Laravel
框架和xampp
搭建一个后台管理系统。因为有需要做webservice接口功能,使用到了php中的soap,然而开发过程中出现了Function doesn't exist
的问题,卡了好久,因此前来求助。具体如下:
有这么两个php文件:
①client.php,作为soap客户端
路径:C:xampphtdocsmy_projectappServicesclient.php
<code class="php"><?php try { $client = new SoapClient(null, array('location' => "http://localhost/my_project/app/Services/server.php", 'uri' => "http://localhost/", 'encoding' => 'UTF-8')); echo $client->hello(); } catch (SoapFault $fault) { echo "Error: ", $fault->faultcode, ", String: ", $fault->getMessage(); }</code>
②server.php,作为soap服务端
路径:C:xampphtdocsmy_projectappServicesserver.php
<code><?php namespace App\Services; use App\User; // User是Laravel中的model,在C:\xampp\htdocs\my_project\app下 try { $soap = new \SoapServer(null, array('uri' => "localhost")); $soap->addFunction('hello'); $soap->handle(); }catch (\SoapFault $fault) { echo "Error: ", $fault->faultcode, ", String: ", $fault->faultstring; } function hello() { $model = new User; return "hello"; }</code>
因为有需要用到模板,因此在server.php
中使用了namespace
,并把User
类用use
的方式引用进来。但是这样一来server.php
中的SoapServer
和SoapFault
前面就要加上斜杠,变成SoapServer
和SoapFault
最后在浏览器中运行C:xampphtdocsmy_projectappServicesclient.php
时却出现了Error: SOAP-ENV:Server, String: Function 'hello' doesn't exist
错误提示,百度谷歌一直未果,希望有经验的前辈能指点一下,不胜感激!