我有3个客户端站点都依赖外部Web服务。 Web服务曾经位于ColdFusion服务器上,但它刚刚更改为.NET服务器。我的客户端代码不再有效,我没有运气修复它。客户端站点在php上并使用nusoap来调用Web服务。
我设置了这个测试,使用像以前一样的wsdl:
<?php
// Call the nuSOAP library
require_once('/home/realtywest/www/lib/nusoap.php');
// Create the client instance
$client = new soapclientnusoap('http://webservices.reiwa.com/RMHPServices/ListingsService.svc?wsdl', true);
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('getListingDetail', array('ListingNumber' => 3000975));
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
该脚本的结果可以在这里看到:http://www.realtywest.com.au/listings/test_wsdl.php
返回内部服务故障..
我搜索了我的问题并发现了这个非常古老的论坛帖子:http://www.sitepoint.com/forums/showthread.php?t=97632他们建议有时.NET Web服务设置不同,而不是将其作为wsdl传递给nusoap,同样在调用实际传入时请求,而不仅仅是一组变量..
所以我试着这样:
<?php
// Call the nuSOAP library
require_once('/home/realtywest/www/lib/nusoap.php');
// Create the client instance
$client = new soapclientnusoap('http://webservices.reiwa.com/RMHPServices/ListingsService.svc', false);
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('getListingDetail', '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:getListingDetail>
<!--Optional:-->
<tem:strListingNumber>3000975</tem:strListingNumber>
</tem:getListingDetail>
</soapenv:Body>
</soapenv:Envelope>');
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
请看这里:http://www.realtywest.com.au/listings/test.php这次获得一个Action Not supported错误..第二条消息中发送的请求是从SOAP UI复制的,我可以在那里获得结果,所以我知道Web服务确实确实工作..
我确信有人可以查看调试信息并知道问题是什么..我真的很感激这方面的任何帮助..
答案 0 :(得分:0)
尝试将编码设置为utf-8。 nusoap默认为ISO-8859-1。我不是一个php开发人员,但我已经做了一段时间的wcf.net到php的事情,这是我遇到的问题。
$wsdl="http://webservices.reiwa.com/RMHPServices/ListingsService.svc?wsdl";
$client=new soapclient($wsdl, 'wsdl');
$client->soap_defencoding = 'utf-8';//default is
$client->response_timeout = 60;//seconds
//paramaters to the webservice
$param=array('ListingNumber' => 3000975);
//the function within the service to call
$result = $client->call('getListingDetail', $param);