关于iOS调用SOAP协议的WebServices接口

在我们做项目的时候,往往移动客户端是现有平台的一个扩展,因此客户端实现往受限于服务采用的技术。那么目前大多数在一个新项目开始的时候,可能会考虑如果要考虑移动客户端的话会提供接口,但是,有些时候服务端已经有接口,而且这个接口可能不仅仅是提供给移动平台使用的,比如它的实现采用的是SOAP协议的WebServices实现。那么这个时候iOS端应该要如何去做呢? 

 

//1. 创建URL

    NSURL *url = [NSURL URLWithString:@"http://www.joy11.com/WebService/LiAnService.asmx"];

    

    //2. 创建请求(post方式创建可变请求)

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    

    //3. 指定请求为post方式

    [request setHTTPMethod:@"POST"];

    

    //4. 准备提交的数据

    NSString *soapMessage = [NSString stringWithFormat:

                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"

                             "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"

                             "<soap12:Header>"

                             "<AuthSoapHd xmlns=\"http://tempuri.org/\">"

                             "<strUserName>lian2014</strUserName>" //填写soap herder账户

                             "<strPassword>lian0403</strPassword>" //填写soap herder密码

                             "</AuthSoapHd>"

                             "</soap12:Header>"

                             "<soap12:Body>"

                             "<LoginLink xmlns=\"http://tempuri.org/\">"

                             "<key>%@</key>" //填写用户Id

                             "</LoginLink>"

                             "</soap12:Body>"

                             "</soap12:Envelope>", [AccountTool sharedAccountTool].currentAccount.uid];

    

    

    

    NSURL *url1 = [NSURL URLWithString:@"http://www.joy11.com/webservice/lianservice.asmx"];

    

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url1];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

 

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[theRequest addValue: @"http://tempuri.org/LoginLink" forHTTPHeaderField:@"SOAPAction"];

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

[theRequest setHTTPMethod:@"POST"];

[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

 

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

代码为直接lain'jie

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值