求助:xcode通过soap获取远程数据库问题

REuser 2014-01-08 02:09:08
实现功能: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。谢谢大家
...全文
346 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hslinux 2014-01-09
  • 打赏
  • 举报
回复
IOS 调用WebService(同步和异步) http://www.cnblogs.com/danye/p/3218832.html 这篇文章也许对你有点用。

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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