求助:xcode通过soap获取远程数据库问题
实现功能:ios客户端查询远程数据库数据并显示
思路:搭建php+mysql 服务器,在服务器上写soap接口负责读取数据数据。ios客户端向服务器发送soap请求,拿到xml返回解析,得到数据并显示。
问题1:怎么写soap接口?这是我写的例子:
soapserver.php
<?php
class service
{
public function search($id) {
$con = mysql_connect("127.0.0.1","root","131400");
mysql_select_db("test",$con);
$sql= "select password from `user` where id=$id";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
return $row[0];
}
} }
$server=new SoapServer('search.wsdl',array('soap_version' => SOAP_1_2));
$server->setClass("service");
$server->handle();
?>
根据soapserver.php 生成了一个wsdl文件
soapclient.php
<?php
$client=new SoapClient("search.wsdl");
//$client->connect();
echo ($client->search(10086));
?>
运行127.0.0.1/promos/soapclient.php,页面显示查到的数据。
在xcode项目中调用search函数:
NSString *id = idNumber.text;
NSString *soapMsg = [NSString stringWithFormat:
@"<?xml version="1.0" encoding="utf-8"?>"
"<soap12:Envelope "
"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" "
"xmlns:xsd="http://www.w3.org/2001/XMLSchema" "
"xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">"
"<soap12:Body>"
"<search xmlns="http://127.0.0.1/promos/">\n"
"<id>%@</id>\n"
"</search>\n"
"</soap12:Body>"
"</soap12:Envelope>", id];
NSURL *url = [NSURL URLWithString: @"http://127.0.0.1/promos/soapserver.php"];
问题2:上面web server 提供的soap接口还差什么东西?还是错了?
问题3:我在xcode的项目中怎么写soap消息格式调用上面我写的search查询函数?
本人实在太菜了,刚刚接触xcode和objective-c。谢谢大家
[解决办法]
IOS 调用WebService(同步和异步)
http://www.cnblogs.com/danye/p/3218832.html
这篇文章也许对你有点用。