PHP nusoap ->webservice

qq_32376649 2016-05-11 10:48:05
服务端
<?php
require_once("lib/nusoap.php");
$server = new soap_server;
//避免乱码
$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->xml_encoding = 'UTF-8';
$server->configureWSDL('sayHello');//打开wsdl支持
/*
注册需要被客户端访问的程序
类型对应值:bool->"xsd:boolean" string->"xsd:string"
int->"xsd:int" float->"xsd:float"
*/
$server->register( 'sayHello', //方法名
array("name"=>"xsd:string"), //参数,默认为"xsd:string"
array("return"=>"xsd:string") );//返回值,默认为"xsd:string"
//isset 检测变量是否设置
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
//service 处理客户端输入的数据
$server->service($HTTP_RAW_POST_DATA);
/**
* 供调用的方法
* @param $name
*/

/*
function sayHello($name) {
return "Hello, {$name}!";
}*/

function sayHello($name) {
$sql = "select issue_no from issue where reported_by='".$name."'";
$result=mysql_query($sql);
while($rows=mysql_fetch_object($result)){
$return.=$rows->issue_no;
}
return "{$return}";
}
?>



服务端
<?php
include 'include/include.php';
$lv_username=$_SESSION['username'];//用户名
require_once("lib/nusoap.php");
/*
通过WSDL调用WebService
参数1 WSDL文件的地址(问号后的wsdl不能为大写)
参数2 指定是否使用WSDL
$client = new soapclient('http://localhost/WebService/nusoapService.php?wsdl',true);
*/
$client = new soapclient('http://192.168.0.144:808/nusoapService.php');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'UTF-8';
//参数转为数组形式传递
$paras=array('name'=>$lv_username);
//目标方法没有参数时,可省略后面的参数
$result=$client->call('sayHello',$paras);
//检查错误,获取返回值
if (!$err=$client->getError()) { echo "返回结果:",$result; }
else { echo "调用出错:",$err; }
?>



报错 :
调用出错:Response not of type text/xml (no content-type header)

昨天 接触这个 求一些实例 谢谢
...全文
138 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
实例: php /* * Company Information * This script is a webservice client that consumes the webservice with * WSDL document at http://www.flash-db.com/services/ws/companyInfo.wsdl * * Given any stock symbol, it queries the webservice for information about * that stock symbol and it retrieves the results from the webservice * for display. * * A live demo of this program can be found at * http://timba.host.sk/companyinfo.php * * I actually noticed that NuSOAP doesn't have very good documentation * and I was thinking of writing one. I am working on my site at * http://timba.host.sk/ and when I am through with it, I would be putting * the documentation there. * * Written by: * Tim Akinbo * Department of Electronic and Electrical Engineering, * Obafemi Awolowo University, * Ile-Ife, Osun State, Nigeria * * Date: January 12, 2003: 23:10:10 GMT+0100 * */ // Include the NuSOAP soap toolkit file. include('nusoap.php'); // Create a SOAP Client object. $client = new soapclient("http://www.flash-db.com/services/ws/companyInfo.wsdl","wsdl"); // The following is a mechanism for capturing the stock symbol we want // to lookup. You can change this as required. $symbol = $_GET['symbol']; // Arguments for the webservice. $args = array ("username"=>"Any", "password"=>"Any", "ticker"=>$symbol); // Call the webservice "doCompanyInfo" method with the arguments. $results = $client->call("doCompanyInfo", $args); /* $results is an array with the following structure Array ( [symbol] => MU [company] => MICRON TECH [lastPrice] => 10.29 [tradedDate] => 1/10/2003 [tradedTime] => 4:01pm [change] => 0.34 [changePercent] => +3.42% [volumne] => 8895900 [averageVolume] => 9653090 [bid] => N/A [ask] => N/A [yesterdayClose] => 9.95 [open] => 10.04 [yearHigh] => 39.5 [yearLow] => 9.40 [dayLow] => 9.90 [dayHigh] => 10.38 [earnPerShare] => -1.59 [PE] => N/A [divDate] => 1-May-00 [yeild] => 0 [divShare] => N/A [marketCap] => 6.226B ) */ // We would now format the data for output in HTML. $html = "\n\nCompany Info. <em>Webservice</em> client - Written by: Tim Akinbo\n\n"; $html .= "\n"; $html .= "\n\n"; $html .= "\n"; $html .= "\n\n\n\n
 Company Info
\n\n\n"; $html .= "\n\n"; $color = "#000000"; // $color is set to green if we have an appreciation in value ("+" present in $results['changePercent']) if (preg_match("/^\+/", $results['changePercent'])) $color = "#00CC33"; // else it is set to red if we have a depreciation ("-") if (preg_match("/^-/", $results['changePercent'])) $color = "#FF0000"; $html .= "\n\n\n"; $html .= "
Company NameStock SymbolPercentage Change
" . $results['company'] . "" . $results['symbol'] . "" . $results['changePercent'] . "
\n
\n\n"; echo $html; ?>

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧