[英]PHP: SOAP Webservice working not properly
我將功能名稱更改為“價格”,使其工作完美,但其他名稱賦予它發生以下錯誤
功能->
<?php
function facto($name)
{
$details= array('abc' =>100 ,'xyz'=>210 );
foreach ($details as $n => $p) {
if($name==$n)
$price=$p+100;
}
return $price;
}
?>
客戶端->
<?php
require 'lib/nusoap.php';
$client=new nusoap_client("http://localhost/WebServicePHP/service1.php?wsdl");
$book_name="abc";
$response=$client->call('facto',array("name"=>"$book_name"));
if(empty($response))
echo "Book data not available";
else
echo $response;
?>
服務->
<?php
require 'functions.php';
require 'lib/nusoap.php';
$server=new nusoap_server();
$server->configureWSDL("demo","urn:demo");
$server- >register("facto",array("name"=>'xsd:string'),
array("return"=>'xsd:intger'));
$HTTP_RAW_POST_DATA=isset($HTTP_RAW_POST_DATA)?
$HTTP_RAW_POST_DATA:'';
$server->service($HTTP_RAW_POST_DATA);
?>
現在它的返回錯誤像
“注意:數組到字符串的轉換
第9行“ C:\\ xampp \\ htdocs \\ WebServiceExp \\ factclient.php”
這是因為您要在參數中傳遞一個數組,並在if
條件中將該數組作為字符串進行比較。
因此更改此行:
$response=$client->call('facto',array("name"=>"$book_name"));
對此:
$response=$client->call('facto',$book_name);
或更改您的if條件:
if($name==$n)
對此:
if(in_array($n,$name))
“注意:第9行數組中C:\\ xampp \\ htdocs \\ WebServiceExp \\ factclient.php中的數組到字符串的轉換”
您在客戶端代碼的9行嘗試回顯數組的問題echo $response;
。 將其更改為var_dump($response);
查看此數組的結構,然后從此數組中回顯適當的值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.