博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SOAP web service用AFNetWorking实现请求
阅读量:5319 次
发布时间:2019-06-14

本文共 2948 字,大约阅读时间需要 9 分钟。

问:

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

NSString *soapMessage =    [NSString stringWithFormat:     @"
" "
" "
" "
" "
%i
" "
%@
" "
%@
" "
" "
" "
", par1, par2, par3 ];NSURL *url = [NSURL URLWithString:@"http://....asmx"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]]; [request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];operation.responseSerializer = [AFXMLParserResponseSerializer serializer];[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if([self.delegate respondsToSelector:@selector(myAppHTTPClientDelegate:didUpdateWithWeather:)]){ [self.delegate myAppHTTPClientDelegate:self didUpdateWithWeather:responseObject]; } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if([self.delegate respondsToSelector:@selector(myAppHTTPClientDelegate:self:didFailWithError:)]){ [self.delegate myAppHTTPClientDelegate:self didFailWithError:error]; } }]; [operation start];
But I need to change this to use
AFHTTPSessionManager.
I suppose that I need to use this:

 

UPDATE

 
NSDictionary *s_request = @{@"par1": [NSString stringWithFormat:@"%i", par1], @"par2": par2, @"par3": par3, @"par4": [NSString stringWithFormat:@"%i", par4], @"par5": par5};    AFHTTPSessionManager* s_manager = [[AFHTTPSessionManager alloc] init];    [s_manager POST:@"http://192.168.10.26/mywebservice/myservice.asmx?op=MethodName" parameters:s_request success:^(NSURLSessionDataTask *task, id responseObject) {        NSLog(@"DONE!");    } failure:^(NSURLSessionDataTask *task, NSError *error) {        NSLog(@"FAILED %@, %@", [error localizedDescription], [error localizedFailureReason]);    }];

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:

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

转载于:https://www.cnblogs.com/blfshiye/p/5244072.html

你可能感兴趣的文章
《当幸福来敲门》读后
查看>>
【转】系统无法进入睡眠模式解决办法
查看>>
省市县,循环组装,整合大数组
查看>>
python--闭包函数、装饰器
查看>>
Phpstorm中使用SFTP
查看>>
stm32中字节对齐问题(__align(n),__packed用法)
查看>>
like tp
查看>>
使用 github Pages 服务建立个人独立博客全过程
查看>>
posix多线程有感--线程高级编程(线程属性函数总结)(代码)
查看>>
spring-使用MyEcilpse创建demo
查看>>
DCDC(4.5V to 23V -3.3V)
查看>>
kettle导数到user_用于left join_20160928
查看>>
activity 保存数据
查看>>
typescript深copy和浅copy
查看>>
linux下的静态库与动态库详解
查看>>
hbuilder调底层运用,多张图片上传
查看>>
深入理解基于selenium的二次开发
查看>>
较快的maven的settings.xml文件
查看>>
Git之初体验 持续更新
查看>>
软件开发模型之瀑布模型
查看>>