如何使用 php 访问我使用 gSoap 和 C++ 创建的 Web 服务?
我创建了 gSOAP 计算器服务示例,位于:http://www.genivia。 com/Products/gsoap/demos/index.html
我的 Web 服务作为守护进程在我的 Solaris 机器上运行。
现在我正在尝试使用 php 页面来访问这个新的网络服务。我一直在查看 http://www.php.net/manual/en/ class.soapclient.php,并尝试制作一个示例,但没有成功。有人可以给我举一个这样做的例子吗?或者告诉我执行此操作的代码?
我花了两天时间浏览网站并尝试不同的东西,但我的项目时间已经不多了。非常感谢您的帮助。
仅供参考:我将 apache 服务器设置为端口 7000。
<?php
function customError($errno, $errstr)
{
echo "<b>Error: </b> [$errno] $errstr";
}
set_error_handler("customError");
define("SOAP_ENCODED", 1);
define("SOAP_RPC", 1);
$options = array(
'compression'=>true,
'exceptions'=>false,
'trace'=>true,
'use' => SOAP_ENCODED,
'style'=> SOAP_RPC,
'location'=> "http://localhost:7000",
'uri' => "urn:calc"
);
echo "1";
$client = @new SoapClient(null, $options);
echo "2";
$args = array(2, 3);
$ret = $client->__soapCall("add", $args);
echo "3";
if (is_soap_fault($ret))
{
echo 'fault : ';
var_dump($client->__getLastRequest());
var_dump($client->__getLastRequestHeaders());
}
else
{
echo 'success : ';
print '__'.$ret.'__';
}
$client->ns__allAllowed();
?>
网页不会返回任何错误。
迈克尔
I have created the gSOAP Calculator Service example found at: http://www.genivia.com/Products/gsoap/demos/index.html
I have my web service running as a deamon on my Solaris box.
Now I'm trying to use a php page to hit this new web service. I have been looking at http://www.php.net/manual/en/class.soapclient.php, and have tried to make an example, but have had no luck. Can someone please point me to an example of doing this? or show me the code for doing it?
I have spent two days looking at web sites and trying different things and am running out of time on my project. Thank you so much for your help.
fyi: I have my apache server set to port 7000.
<?php
function customError($errno, $errstr)
{
echo "<b>Error: </b> [$errno] $errstr";
}
set_error_handler("customError");
define("SOAP_ENCODED", 1);
define("SOAP_RPC", 1);
$options = array(
'compression'=>true,
'exceptions'=>false,
'trace'=>true,
'use' => SOAP_ENCODED,
'style'=> SOAP_RPC,
'location'=> "http://localhost:7000",
'uri' => "urn:calc"
);
echo "1";
$client = @new SoapClient(null, $options);
echo "2";
$args = array(2, 3);
$ret = $client->__soapCall("add", $args);
echo "3";
if (is_soap_fault($ret))
{
echo 'fault : ';
var_dump($client->__getLastRequest());
var_dump($client->__getLastRequestHeaders());
}
else
{
echo 'success : ';
print '__'.$ret.'__';
}
$client->ns__allAllowed();
?>
The web page does not return any errors.
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在脚本顶部:
需要检查的一些事项:
?>
后没有空格(您应该将其删除)php /path/myscript.php
At the top of the script:
Some things to check:
?>
(You should just remove it)php /path/myscript.php
在您提到的教程中,Calc Web 服务生成 WSDL。 WSDL 是一个描述 Web 服务的所有方法和类型的文件。记住这一点,您可以在 PHP 中创建 SOAP 客户端:
然后您可以调用 Web 服务提供的任何方法:
如果发生某些错误,您将在 try/catch 块中捕获它。
In the tutorial you mentioned written that Calc web service generates WSDL. WSDL is a file that describes all methods and types of web service. Keeping this in mind you can create SOAP client in PHP:
Then you can call any method provided by Web service:
If some error will occur you'll catch it in try/catch block.