连接到 .NET 服务器时出现 PHP nuSoap 问题:“对象引用未设置到对象的实例。”
我目前正在使用 PHP 开发 SOAP 项目。该脚本正在连接到远程 .NET 服务服务器。我使用提供的 HelloWorld 操作得到了很好的响应,但是当脚本使用其他操作获取任何其他数据时,我得到
“未将对象引用设置为对象的实例。”
位于 $data 数组 的 diffgram 子数组中(见下文)。
这是当前代码,不包括服务 URL 和参数。
<?php
require_once('../lib/nusoap.php');
$options = array(
# server
'wsdl' => false,
'srvr' => 'http://test.domain.com/soap/file.asmx',
'base' => 'http://sub.domain.com/',
'act' => isset($_POST['act']) ? $_POST['act'] : 'RequestSomething',
'curl' => isset($_POST['curl']) ? $_POST['curl'] : false,
'char' => 'UTF-8',
# proxy
'host' => isset($_POST['host']) ? $_POST['host'] : false,
'port' => isset($_POST['port']) ? $_POST['port'] : false,
'user' => isset($_POST['user']) ? $_POST['user'] : false,
'pass' => isset($_POST['pass']) ? $_POST['pass'] : false,
);
$client = new nusoap_client(
$options['srvr'], $options['wsdl'],
$options['host'], $options['port'], $options['user'], $options['pass']
);
$client->soap_defencoding = $options['char'];
$client->setUseCurl($options['curl']);
$error = $client->getError();
if($error){
$debug = htmlspecialchars($client->getDebug(), ENT_QUOTES);
echo "<h2>Error</h2><pre>$error</pre>";
echo "<h2>Debug</h2><pre>$debug</pre>";
exit;
}
$params = array(
'ID' => 123,
);
$send = $params;
$do = $options['base'] . $options['act'];
$data = $client->call($options['act'], $send, $do, $do);
if($data && $data = (array) $data) {
echo "<h2>Call data</h2>";
echo "<pre>" . print_r($data,true) . "</pre>";
}
?>
I am currently working on a SOAP project using PHP. The script is connecting to a remote .NET service server. I get a nice response using the HelloWorld action the provide, but when the script goes to get any other data using other actions, I get
"Object reference not set to an instance of an object."
in a diffgram sub array of the $data array (see below).
Here is the current code, excluding the service URLs and params.
<?php
require_once('../lib/nusoap.php');
$options = array(
# server
'wsdl' => false,
'srvr' => 'http://test.domain.com/soap/file.asmx',
'base' => 'http://sub.domain.com/',
'act' => isset($_POST['act']) ? $_POST['act'] : 'RequestSomething',
'curl' => isset($_POST['curl']) ? $_POST['curl'] : false,
'char' => 'UTF-8',
# proxy
'host' => isset($_POST['host']) ? $_POST['host'] : false,
'port' => isset($_POST['port']) ? $_POST['port'] : false,
'user' => isset($_POST['user']) ? $_POST['user'] : false,
'pass' => isset($_POST['pass']) ? $_POST['pass'] : false,
);
$client = new nusoap_client(
$options['srvr'], $options['wsdl'],
$options['host'], $options['port'], $options['user'], $options['pass']
);
$client->soap_defencoding = $options['char'];
$client->setUseCurl($options['curl']);
$error = $client->getError();
if($error){
$debug = htmlspecialchars($client->getDebug(), ENT_QUOTES);
echo "<h2>Error</h2><pre>$error</pre>";
echo "<h2>Debug</h2><pre>$debug</pre>";
exit;
}
$params = array(
'ID' => 123,
);
$send = $params;
$do = $options['base'] . $options['act'];
$data = $client->call($options['act'], $send, $do, $do);
if($data && $data = (array) $data) {
echo "<h2>Call data</h2>";
echo "<pre>" . print_r($data,true) . "</pre>";
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 soapUI (有免费版本)或其他类似的 SOAP 测试客户端,并确保您使用的 Web 服务消费实际上按预期进行。如果确实如此,那么请担心您的代码。
Try soapUI (there's a free version) or another similar SOAP test client and make sure that the web service you're consuming actually works as expected. If it does, then worry about your code.