IOS访问webserver接口

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

接口调用参数只能是字符串格式,返回格式支持3种(字符串,数组,DataSet)

需要引用第三方库,包含(DataSet,PlatServinceDataParser,WebserviceCommon,WebServiceHelper,xmlArrayParser,XMLDataSetParser,XMLResultParser)

程序中引用2个即可

#import "WebServiceCommon.h"

#import"DataSet.h"

- (void)getwebserver

{

WebServiceCommon *webService=[[WebServiceCommonalloc] init];

//方法一,取返回字符串

NSString *result= [webServicegetResultWithURL:@"http://116.6.52.27:91/webservice/caskaforescService.asmx"xmlNS:nilmethod:@"GetCarTypeTree"pars:nil];

NSLog(@"%@",result);

[result release];

//带参数传值调用方法

NSMutableDictionary *dic=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"test2",@"username",@"820826",@"passWord",@"1EB2D9848C5545E6BAEAA10B01222800",@"clubUserid",@"西南大区",@"BigArea",@"",@"PRovince",@"",@"city",nil];

NSString *result2= [webServicegetResultWithURL:@"http://116.6.52.27:91/webservice/caskaforescService.asmx"xmlNS:nilmethod:@"GetClub"pars:dic];

NSLog(@"%@",result2);

[dic release];

[result2 release];

//方法二,取返回数据组

NSArray *array=nil;

NSMutableDictionary *dic2=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"...",@"VerifyCode", @"",@"objParams",@"20120615170225282486",@"sAccountBookID", @"XYTY124",@"productModel", @"馨原奕绒",@"brandName", nil];

array=[webServicegetArrayWithURL:@"http://resourceservice.41go.cn/systemupdate.asmx"xmlNS:nilmethod:@"GetProductPriceInfoExt"pars:dic2];

NSLog(@"productmodel=%@;name=%@,key=%@",[arrayobjectAtIndex:2],[arrayobjectAtIndex:3],[arrayobjectAtIndex:10]);

//判断数据中的空值(NSArray,NSMutableDictionary等)

if ([array objectAtIndex:10]==[NSNullnull]) {

NSLog(@"空值!");

}

[dic2 release];

//方法三,取返回DataSet

[webServiceinitDataSetWithURL:@"http://resourceservice.41go.cn/systemupdate.asmx"xmlNS:nilmethod:@"GetYarnList"pars:nil];

NSMutableDictionary *wb=[webService.myDataset.TablesobjectForKey:@"YarnList"];//YarnList表名,如果没有命名则为Table

NSInteger count=[[webService.myDataset.TablesobjectForKey:@"YarnList"]count];

for (int ii=0; ii<count; ii++) {

NSMutableDictionary *dictemp=[wb objectForKey:[NSStringstringWithFormat:@"%d",ii]];

NSLog(@"col1=%@;col2=%@;col3=%@",[dictempobjectForKey:@"C_AccountBookID"],[dictempobjectForKey:@"C_Name"],[dictempobjectForKey:@"C_YarnID"]);

}

[webService release];

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航