欢迎访问论坛: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里面
命令运行完之后会生成许多文件
![](https://img-my.csdn.net/uploads/201212/13/1355367332_4781.png)
将这些文件都放到一个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