IOS下使用GSOAP(客户端)

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

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


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

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

cd  /Users/jilucky/Desktop/zzzili/gsoap/qxd
./wsdl2h -o QXDService.h  http://192.168.1.100:1000/ClientService.asmx?WSDL
./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

//
//  CGsoap.h


#import <Foundation/Foundation.h>
#import "soapStub.h"
#import "gsoapios.h"


@interface CGsoap :NSObject
{
    struct soap *m_soap;
 
}

-(id)init;
-(BOOL) Login:(NSString*)userId pass:(NSString*)_pass;


@end



//
//  CGsoap.m


#import "CGsoap.h"


NSString* DecodeUtf8(std::string* s)
{    
    if(s==NULL)
        return @"";
    NSString *strName = [NSString stringWithCString:s->c_str() encoding:NSUTF8StringEncoding];
    const char *abc = [strName  cStringUsingEncoding:NSUTF8StringEncoding];        
    NSString *str = [[NSString alloc] initWithBytes:abc length:strlen(abc) encoding:NSUTF8StringEncoding]; 
    return str;
}

@implementation CGsoap

-(id)init
{
    m_soap = new struct soap;
    soap_init(m_soap);
    soap_set_mode(m_soap, SOAP_C_UTFSTRING);
    m_soap->mode|=SOAP_C_UTFSTRING;    
    return (self);
}

-(Member*) Login:(NSString*)phone pass:(NSString*)_pass
{
    _ns1__UserLogin request;
    request.phone = new std::string([phone UTF8String]);
    request.pss   =  new std::string([_pass UTF8String]);
    _ns1__UserLoginResponse response;
    
    
    if(SOAP_OK== soap_call___ns2__UserLogin(m_soap, NULL, NULL, &request, &response))
    {
        if(response.UserLoginResult->Name != nil)
        {
            ns1__Member *resm = response.UserLoginResult;
            Member *member = new Member;
            NSLog(@"login success");
            member->Id = resm->Id;
            member->Name = DecodeUtf8(resm->Name);
            member->Phone = DecodeUtf8(resm->Phone);
            member->Ps = DecodeUtf8(resm->Ps);
            
            return member;
        }
    }
    return nil;
    
}


@end


IOS 中图片的上传

UIImage *image= [info objectForKey:UIImagePickerControllerOriginalImage];
	NSString *filePath = [NSTemporaryDirectory() stringByAppendingFormat:@"tmp.png"];
    NSLog(@"filename is %@", filePath);
    
    [UIImageJPEGRepresentation(image, 0) writeToFile:filePath atomically:YES];
    
    NSData *tData = [NSData dataWithContentsOfFile:filePath];
    imageData = [tData mutableCopy];
[g_soap GetImagePath:imageData];




-(NSString *)GetImagePath:(NSData *)image
{
    NSString *path = [[NSString alloc]initWithFormat:@""];
    _ns1__getImageByte request;
    xsd__base64Binary *newByte = new xsd__base64Binary;
    newByte->__ptr = (unsigned char*)image.bytes;
    newByte->__size = image.length;
    request.getByte = newByte;
    _ns1__getImageByteResponse response;
    
    soap_call___ns3__getImageByte(m_soap, NULL, NULL, &request, &response);
    path = DecodeUtf8(response.getImageByteResult);
    NSLog(@"image path is %@",path);
    return path;
}

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


交流qq:825127671

转载于:https://www.cnblogs.com/zzili/archive/2012/12/13/6663217.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值