iOS 基于WebService开发

1.通过WSDL2ObjC调用WebService接口

利用 WSDL2ObjC 这个工具直接转换为OC类


第一个为WebService的地址 第二个为生成的OC类存放的位置  然后点击Parse WSDL 就OK了  

生成文件如下图(因为服务不一样生成的第一个文件名会不同):


将生成的类直接拖入工程就可以用了 

生成的文件一般为MRC 需要转为ARC

可能出现的错误   libxml/tree.h” file not found  

解决方法 

TARGETS->Build Settings->Linking->Other Linker Flags 设置"-lxml2"

TARGETS->Build Settings->Search Paths->Header Search Paths 设置"/usr/include/libxml2"

TARGETS->Build Settings->Apple LLVM5.0-Language-Objective-Objective C->Objective-C Automatic Reference Counting 设置"NO"


(注意一旦服务增加新的方法或者更改参数、添加属性就需要重新更新服务)

2.接下来就是请求数据了

头文件包含生成方法的类 在我这里是MobileHiSService.h 遵守<MobileHISServiceSoap12BindingResponseDelegate> 协议 (对应的协议)

实现协议中方法

- (void)operation:(MobileHISServiceSoap12BindingOperation *)operation completedWithResponse:(MobileHISServiceSoap12BindingResponse *)response

这个方法就是服务返回的响应

MobileHISService_GetAllKeyBoard *request = [[ MobileHISService_GetAllKeyBoard alloc] init];  //GetAllKeyBoard为服务的方法名

    request.TemplateID = @"1";                                                               // 服务中规定的参数

    MobileHISServiceSoap12Binding *binding = [[MobileHISServiceSoap12Binding alloc] initWithAddress:@"http://172.18.98.40:8080/MobileHISService.asmx"];                          // 服务的地址

    binding.defaultTimeout = 20;                                                             // 默认20s后超时

   

[binding GetAllKeyBoardAsyncUsingParameters:request delegate:self];                          // 调用服务的方法()


再举个例子 这里有个公共的WebService接口

http://webservice.36wu.com/weatherService.asmx

首先需要在WSDL2Objc 工具的第一行中输入http://webservice.36wu.com/weatherService.asmx?wsdl  (注意后面要改为?wsdl)

然后再生成OC类 如下图

  

然后拖入工程中

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor redColor];

    WeatherService_getExponentByCityName *request = [[WeatherService_getExponentByCityName alloc] init];

    request.CityName = @"beijing";

    request.UserId = @"";

    WeatherServiceSoap12Binding *binding = [[WeatherServiceSoap12Binding alloc] initWithAddress:@"http://webservice.36wu.com/weatherService.asmx"];

    [binding getExponentByCityNameAsyncUsingParameters:request delegate:self];

}


- (void)operation:(WeatherServiceSoapBindingOperation *)operation completedWithResponse:(WeatherServiceSoapBindingResponse *)response

{

    

}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值