Home  >  Article  >  Backend Development  >  php写WebService无法通信,该怎么解决

php写WebService无法通信,该怎么解决

WBOY
WBOYOriginal
2016-06-13 11:50:341071browse

php写WebService无法通信
客户端代码:

<br /><?php<br />    $client = new SoapClient(null, array('location'=>"http://192.168.1.100/test/serverSoap.php",'uri' =>"http://soap/"));<br />    echo $client->show();  <br />?><br />

服务器代码:
<br /><?php<br />    class test{<br />        function show(){<br />            return 'the data you request';<br />        }<br />    }<br />    function getUserInfo($name){<br />        return 'fbbin';<br />    }<br />    $soap = new SoapServer(null, array('uri'=>'http://soap/','location'=>'http://localhost/test/serverSoap.php'));<br />    $server->serClass('test');<br />    $server->handle();<br />?><br />

运行环境用的wamp,以上两个文件都放在wamp安装目录的www/test/目录下。

操作系统window 8

打开浏览器,访问客户端文件

http://localhost/test/serverClient.php

显示错误信息如下:

我是新手啊,php刚学没几天,webservice也只是知道用来干啥的,从来没用过。麻烦诸位讲的通俗一点可不可以啊,谢谢回答。

php的soap服务以打开。
php的soap服务以开启:

------解决方案--------------------
太粗心了,这样写
<?php<br />    class test{<br />        function show(){<br />            return 'the data you request';<br />        }<br />    }<br />    function getUserInfo($name){<br />        return 'fbbin';<br />    }<br />    $server = new SoapServer(null, array('uri'=>'http://soap/','location'=>'http://localhost/test/serverSoap.php'));<br />    $server->setClass('test');<br />    $server->handle();<br />?>

------解决方案--------------------
补充下

<br /><?php<br />    class test{<br />        function show(){<br />            return 'the data you request';<br />        }<br /><br />        function getUserInfo($name){<br />            return 'fbbin';<br />        }<br />    }<br />    $server = new SoapServer(null, array('uri'=>'http://soap/','location'=>'http://localhost/test/serverSoap.php'));<br />    $server->setClass('test');<br />    $server->handle();<br />?><br />

Statement:
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