足球游戏_中国足彩网¥体育资讯$

制作iphone的soap应用
来源:易贤网 阅读:653 次 日期:2015-02-03 14:32:25
温馨提示:易贤网小编为您整理了“制作iphone的soap应用”,方便广大网友查阅!

为 了便于理解,我先讲下soap的大体原理:我们在iphone封装soap请求信息,发送到某个提供soap服务的服务器,如下例中我们用到的.服 务器能接受和识别soap请求,当它接到请求,就根据客户端的请求情况调用服务器上的某个函数,并将函数返回结果封装成soap反馈信息发送给客户端.客 户端接收到soap反馈信息后,进行解析处理,以用户能理解的形式呈现给用户.整个过程就这么简单.

好了,假设现在你已经有关于 soap的基础知识(没有也没关系,看了例子,再理解就更好理解了),下面我们开始做soap的例子.

第一步,建一个 hello_soap项目.用ib将hello_soapviewcontroller.xib做成如下图的界面

然后在hello_soapviewcontroller.h中添加如下代码

代码如下:

1. @interface hello_soapviewcontroller : uiviewcontroller 2. { 3. iboutlet uitextfield *nameinput; 4. iboutlet uilabel *greeting; 5. 6. nsmutabledata *webdata; 7. nsmutablestring *soapresults; 8. nsxmlparser *xmlparser; 9. bool recordresults; 10. } 11. 12. @property(nonatomic, retain) iboutlet uitextfield *nameinput; 13. @property(nonatomic, retain) iboutlet uilabel *greeting; 14. 15. @property(nonatomic, retain) nsmutabledata *webdata; 16. @property(nonatomic, retain) nsmutablestring *soapresults; 17. @property(nonatomic, retain) nsxmlparser *xmlparser; 18. 19. -(ibaction)buttonclick: (id) sender; 20. - (void)getoffesetutctimesoap;

然后在hello_soapviewcontroller.xib中将两个输出口和一个动作连接好,这个不用手把手吧?

在 hello_soapviewcontroller.m文件中加入以下方法 :

代码如下:

1. - (void)getoffesetutctimesoap 2. { 3. recordresults = no; 4.//封装soap请求消息 5. nsstring *soapmessage = [nsstring stringwithformat: 6. @n 7. n 8. n 9. n 10. 11. n 12. n 13. n,nameinput.text 14. ]; 15. nslog(soapmessage); 16. //请求发送到的路径 17. nsurl *url = [nsurl urlwithstring:@]; 18. nsmutableurlrequest *therequest = [nsmutableurlrequest requestwithurl:url]; 19. nsstring *msglength = [nsstring stringwithformat:@%d, [soapmessage length]]; 20. 21. // 以下对请求信息添加属性前四句是必有的,第五句是soap信息。 22. [therequest addvalue: @text/xml; charset=utf-8 forhttpheaderfield:@content-type]; 23. [therequest addvalue: @ forhttpheaderfield:@soapaction]; 24. 25. [therequest addvalue: msglength forhttpheaderfield:@content-length]; 26. [therequest sethttpmethod:@post]; 27. [therequest sethttpbody: [soapmessage datausingencoding:nsutf8stringencoding]]; 28. 29. // 请求 30. nsurlconnection *theconnection = [[nsurlconnection alloc] initwithrequest:therequest delegate:self]; 31. 32. // 如果连接已经建好,则初始化data 33. if( theconnection ) 34. { 35. webdata = [[nsmutabledata data] retain]; 36. } 37. else 38. { 39. nslog(@theconnection is null); 40. } 41. 42. 43. }

这个方法作用就是封装soap请求,并向服务器发送请求.

代码有注释.不重复讲解.soap并不难,难的是没有案例告诉我们怎么把其它平台的 soap移植过来,这里我给出了代码,我相信对iphone开发人员的话应该能看懂了.我在下面会把此案例的源代码附上.如果自己做不出来再看我的代码. 如果我这样讲您觉得不够细,那说明您的iphone开发还不是太深入,那么您应该用不到soap技术.可以飘过了.

下面的代码是接收信息并解析, 显示到用户界面

代码如下:

1. -(void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response 2. { 3. [webdata setlength: 0]; 4. nslog(@connection: didreceiveresponse:1); 5. } 6. -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data 7.{ 8. [webdata appenddata:data]; 9. nslog(@connection: didreceivedata:2); 10. 11. } 12. 13. //如果电脑没有连接网络,则出现 此信息(不是网络服务器不通) 14. -(void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error 15. { 16. nslog(@error with theconenction); 17. [connection release]; 18. [webdata release]; 19. } 20. -(void)connectiondidfinishloading:(nsurlconnection *)connection 21. { 22. nslog(@3 done. received bytes: %d, [webdata length]); 23. nsstring *thexml = [[nsstring alloc] initwithbytes: [webdata mutablebytes] length:[webdata length] encoding:nsutf8stringencoding]; 24. nslog(thexml); 25. [thexml release]; 26. 27. //重新加蒌xmlparser 28. if( xmlparser ) 29. { 30. [xmlparser release]; 31. } 32. 33. xmlparser = [[nsxmlparser alloc] initwithdata: webdata]; 34. [xmlparser setdelegate: self]; 35. [xmlparser setshouldresolveexternalentities: yes]; 36. [xmlparser parse]; 37. 38. [connection release]; 39. //[webdata release]; 40. }

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看技术文章
易贤网手机网站地址:制作iphone的soap应用
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标