Heim  >  Artikel  >  Backend-Entwicklung  >  laravel5.1 - PHP中使用Soap出现Function doesn't exist问题,如何解决?

laravel5.1 - PHP中使用Soap出现Function doesn't exist问题,如何解决?

WBOY
WBOYOriginal
2016-06-06 20:26:461188Durchsuche

在下新手,正在用Laravel框架和xampp搭建一个后台管理系统。因为有需要做webservice接口功能,使用到了php中的soap,然而开发过程中出现了Function doesn't exist的问题,卡了好久,因此前来求助。具体如下:

有这么两个php文件:
①client.php,作为soap客户端
路径:C:\xampp\htdocs\my_project\app\Services\client.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:\xampp\htdocs\my_project\app\Services\server.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中的SoapServerSoapFault前面就要加上斜杠,变成\SoapServer\SoapFault

最后在浏览器中运行C:\xampp\htdocs\my_project\app\Services\client.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:\xampp\htdocs\my_project\app\Services\client.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:\xampp\htdocs\my_project\app\Services\server.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中的SoapServerSoapFault前面就要加上斜杠,变成\SoapServer\SoapFault

最后在浏览器中运行C:\xampp\htdocs\my_project\app\Services\client.php时却出现了Error: SOAP-ENV:Server, String: Function 'hello' doesn't exist错误提示,百度谷歌一直未果,希望有经验的前辈能指点一下,不胜感激!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn