问:

This is my current call to (asmx) SOAP web service:

  1. NSString *soapMessage =
  2. [NSString stringWithFormat:
  3. @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  4. "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
  5. "<soap:Body>"
  6. "<Save xmlns=\"http://www.myapp.com/\">"
  7. "<par1>%i</par1>"
  8. "<par2>%@</par2>"
  9. "<par3>%@</par3>"
  10. "</Save>"
  11. "</soap:Body>"
  12. "</soap:Envelope>", par1, par2, par3
  13. ];
  14. NSURL *url = [NSURL URLWithString:@"http://....asmx"];
  15. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
  16.  
  17. NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];
  18.  
  19. [request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  20. [request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
  21.  
  22. [request setHTTPMethod:@"POST"];
  23. [request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
  24.  
  25. AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
  26. operation.responseSerializer = [AFXMLParserResponseSerializer serializer];
  27. [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
  28. if([self.delegate respondsToSelector:@selector(myAppHTTPClientDelegate:didUpdateWithWeather:)]){
  29. [self.delegate myAppHTTPClientDelegate:self didUpdateWithWeather:responseObject];
  30. }
  31. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  32. if([self.delegate respondsToSelector:@selector(myAppHTTPClientDelegate:self:didFailWithError:)]){
  33. [self.delegate myAppHTTPClientDelegate:self didFailWithError:error];
  34. }
  35. }];
  36.  
  37. [operation start];

But I need to change this to use AFHTTPSessionManager.

I suppose that I need to use this:

  1.  
  2. UPDATE
  3. NSDictionary *s_request = @{@"par1": [NSString stringWithFormat:@"%i", par1], @"par2": par2, @"par3": par3, @"par4": [NSString stringWithFormat:@"%i", par4], @"par5": par5};
  4.     AFHTTPSessionManager* s_manager = [[AFHTTPSessionManager alloc] init];
  5.     [s_manager POST:@"http://192.168.10.26/mywebservice/myservice.asmx?op=MethodName" parameters:s_request success:^(NSURLSessionDataTask *task, id responseObject) {
  6.         NSLog(@"DONE!");
  7.     } failure:^(NSURLSessionDataTask *task, NSError *error) {
  8.         NSLog(@"FAILED %@, %@", [error localizedDescription], [error localizedFailureReason]);
  9.     }];
  10. This code always fail. Getting error 500. Do I just need to add method URL or I need to add complete soap message somewhere. What I miss here?

答:

You need to pass parameter in Dictionary like in the following example:

  1. NSDictionary *request = @{@"email": self.email.text, @"password": self.password.text};
  2. [manager POST:login parameters:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
  3. NSLog(@"DONE!");
  4. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  5. NSLog(@"Failed to log in: %@", operation.responseString);
  6. }];

SOAP web service用AFNetWorking实现请求的更多相关文章

  1. 翻译-使用Spring调用SOAP Web Service

    原文链接: http://spring.io/guides/gs/consuming-web-service/ 调用SOAP web service 本指南将指导你使用Spring调用一个基于SOAP ...

  2. 翻译-使用Spring WebService生成SOAP Web Service

    原文链接:http://spring.io/guides/gs/producing-web-service/ 生成SOAP web service 该指南将带领你使用Spring创建一个基于SOAP的 ...

  3. PHP soap Web Service 使用SoapDiscovery.class.php 生成wsdl文件

    PHP soap web service 使用wsdl文件 demo: ============================================================== 服 ...

  4. REST和SOAP Web Service的区别比较

    本文转载自他人的博客,ArcGIS Server 推出了 对 SOAP 和 REST两种接口(用接口类型也许并不准确)类型的支持,本文非常清晰的比较了SOAP和Rest的区别联系! ///////// ...

  5. 如何在symfony 控制器里面创建soap web service

    通过一些工具将一个控制器设置成一个soap服务将会非常简单.首先,你必须安装了php soap扩展.由于php soap扩展现在不能生成wsdl,你要么自己从头开始创建要模使用第三方生成器. php中 ...

  6. jboss上的soap web service开发示例

    以下示例,由jboss quickstart示例代码得来: 一.创建一个常规的dynamic web项目,建议支持maven ,项目的关键属性参考下图: 二.定义服务接口及参数对象 HelloWorl ...

  7. CXF、Spring整合的SOAP Web Service服务端

    1.建工程,导入CXFjar包 2.服务接口 package com.cxf.soap; import java.util.List; import javax.jws.WebService; @We ...

  8. 使用CXF框架集成Spring实现SOAP Web Service

  9. REST和SOAP Web Service的比较

    1.http://stevenjohn.iteye.com/blog/1442776 2.http://blog.csdn.net/cnyyx/article/details/7483766

随机推荐

  1. UVA 11294 Wedding

    给n对夫妇安排座位,其中0h,0w分别表示新郎,新娘.同一对新郎,新娘不能坐在同一侧,而且互为通奸关系的人不能同时坐在新娘对面. 这道题目真是掉尽节操啊,,,欧美的氛围还是比较开放的. 分析: 首先说 ...

  2. Android ListView(Selector 颜色)

    listview_color.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...

  3. Java缓存--JCS

    添加外部包: jcs-1.3.jar concurrent-10.3.jar cache.cff # optional region "myCache" specific conf ...

  4. C# Eval在asp.net中的用法及作用

    Eval( " ")和Bind( " ") 这两种一个单向绑定,一个双向绑定,bind是双向绑定,但需数据源支持 ASP.NET 2.0改善了模板中的数据绑定操 ...

  5. 很受欢迎的Linux笔记(短小精悍)

    http://blog.csdn.net/xsl1990/article/details/8274028 如何知道所使用的LINUX是哪个发行版? lsb_release -a 查找某个文件的另类方法 ...

  6. Android-相册效果(图片缩放 自由滑动)

    先上图: 很多时候 我们会有这么一个需求: 展示一组图片 每个Item的图片 可以自由拉伸 滑动 焦点不冲突 网上有很多实现方法 通过自定义Gallery和ImageView来实现 个人不是很推荐 在 ...

  7. ActionBar官方教程(1)简介及各区域介绍

    Action Bar The action bar is a window feature that identifies the user location, and provides user a ...

  8. Android 导出db并查看内容

    1.导出sqlite的db文件: 使用工具DDMS,切换到DDMS,显示File Explorer窗口,找到/data/data/应用名/databases/数据库名,点击导出按钮,导出文件. 2.使 ...

  9. HTML <!--...--> 注释标签

    HTML <!--...--> 注释标签 实例 HTML 注释: <!--这是一个注释,注释在浏览器中不会显示--> <p>这是一个段落</p>   浏 ...

  10. C#创建https请求并使用pfx证书

    常规情况下创建Web请求,并获取请求数据的代码如下: WebRequest req = WebRequest.Create(url); req.Timeout = 15000; WebResponse ...