IOS下使用GSOAP(客户端)

举报
清雨小竹 发表于 2022/09/25 00:42:33 2022/09/25
【摘要】 欢迎访问论坛:http://www.chinadev.cn http://download.csdn.net/detail/zzzili/4881810 1.根据Wsdl文件地址生成客户端文件 下载文件,然后在控制台下输入一下命令 cd /Users/jilucky/Desktop/zzzili/gsoap/qx...

欢迎访问论坛:http://www.chinadev.cn

http://download.csdn.net/detail/zzzili/4881810


1.根据Wsdl文件地址生成客户端文件

下载文件,然后在控制台下输入一下命令


  
  1. cd /Users/jilucky/Desktop/zzzili/gsoap/qxd
  2. ./wsdl2h -o QXDService.h http://192.168.1.100:1000/ClientService.asmx?WSDL
  3. ./soapcpp2 -C -x QXDService.h

wsdl2h  和soapcpp2在我发的file.zip里面

命令运行完之后会生成许多文件



将这些文件都放到一个gsoap文件夹里面去(添加进去gsoapios.h和gsoapios.m)


2.xcode新建ios工程,添加gsoap文件夹(此处还要加入stdsoap2.cpp 和stdsoap2.h 文件,我漏掉了)


3.在main.m文件中添加

#import "Gsoap/FriendGPSSoap.nsmap"  ///文件名根据你的情况而定

在ViewController.m中添加

#import "soapStub.h"

#import "gsoapios.h"


4.build setting 中GCC_INPUT_FILETYPE  设置为Objective-C++  ///会出现vector.h找不到

5.build工程,会出现lib错误,这个时候吧gsoap中的soapClientLib.cpp文件移除,再次运行



********另外附送本人写的soap分装类 CSoap.h


  
  1. //
  2. // CGsoap.h
  3. #import <Foundation/Foundation.h>
  4. #import "soapStub.h"
  5. #import "gsoapios.h"
  6. @interface CGsoap :NSObject
  7. {
  8. struct soap *m_soap;
  9. }
  10. -(id)init;
  11. -(BOOL) Login:(NSString*)userId pass:(NSString*)_pass;
  12. @end




  
  1. //
  2. // CGsoap.m
  3. #import "CGsoap.h"
  4. NSString* DecodeUtf8(std::string* s)
  5. {
  6. if(s==NULL)
  7. return @"";
  8. NSString *strName = [NSString stringWithCString:s->c_str() encoding:NSUTF8StringEncoding];
  9. const char *abc = [strName cStringUsingEncoding:NSUTF8StringEncoding];
  10. NSString *str = [[NSString alloc] initWithBytes:abc length:strlen(abc) encoding:NSUTF8StringEncoding];
  11. return str;
  12. }
  13. @implementation CGsoap
  14. -(id)init
  15. {
  16. m_soap = new struct soap;
  17. soap_init(m_soap);
  18. soap_set_mode(m_soap, SOAP_C_UTFSTRING);
  19. m_soap->mode|=SOAP_C_UTFSTRING;
  20. return (self);
  21. }
  22. -(Member*) Login:(NSString*)phone pass:(NSString*)_pass
  23. {
  24. _ns1__UserLogin request;
  25. request.phone = new std::string([phone UTF8String]);
  26. request.pss = new std::string([_pass UTF8String]);
  27. _ns1__UserLoginResponse response;
  28. if(SOAP_OK== soap_call___ns2__UserLogin(m_soap, NULL, NULL, &request, &response))
  29. {
  30. if(response.UserLoginResult->Name != nil)
  31. {
  32. ns1__Member *resm = response.UserLoginResult;
  33. Member *member = new Member;
  34. NSLog(@"login success");
  35. member->Id = resm->Id;
  36. member->Name = DecodeUtf8(resm->Name);
  37. member->Phone = DecodeUtf8(resm->Phone);
  38. member->Ps = DecodeUtf8(resm->Ps);
  39. return member;
  40. }
  41. }
  42. return nil;
  43. }
  44. @end


IOS 中图片的上传


  
  1. UIImage *image= [info objectForKey:UIImagePickerControllerOriginalImage];
  2. NSString *filePath = [NSTemporaryDirectory() stringByAppendingFormat:@"tmp.png"];
  3. NSLog(@"filename is %@", filePath);
  4. [UIImageJPEGRepresentation(image, 0) writeToFile:filePath atomically:YES];
  5. NSData *tData = [NSData dataWithContentsOfFile:filePath];
  6. imageData = [tData mutableCopy];
  7. [g_soap GetImagePath:imageData];
  8. -(NSString *)GetImagePath:(NSData *)image
  9. {
  10. NSString *path = [[NSString alloc]initWithFormat:@""];
  11. _ns1__getImageByte request;
  12. xsd__base64Binary *newByte = new xsd__base64Binary;
  13. newByte->__ptr = (unsigned char*)image.bytes;
  14. newByte->__size = image.length;
  15. request.getByte = newByte;
  16. _ns1__getImageByteResponse response;
  17. soap_call___ns3__getImageByte(m_soap, NULL, NULL, &request, &response);
  18. path = DecodeUtf8(response.getImageByteResult);
  19. NSLog(@"image path is %@",path);
  20. return path;
  21. }


  
  1. //sdk中提供了方法可以直接调用
  2. UIImage *img = [UIImage imageNamed:@"some.png"];
  3. NSData *dataObj = UIImageJPEGRepresentation(img, 1.0);


交流qq:825127671

文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。

原文链接:zzzili.blog.csdn.net/article/details/8289628

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。