专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Iphone

xcode通过soap获取远程数据库有关问题

发布时间:2010-05-30 00:35:56 文章来源:www.iduyao.cn 采编人员:星星草
求助: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
这篇文章也许对你有点用。

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: