搞了两天了AFNetworking 访问WebService.asmx一直都是不成功,帮忙一下!

11个口袋 2016-05-26 07:40:03
我是用VS+c#写的一个简单的服务:服务要求输入一个给定的密码:123456就返回0;
IE,打开:http://192.168.3.110/ATXWebService.asmx?op=login 可以打开,是内网的IP.
打开后里面调用信息如下:

login 测试
测试窗体只能用于来自本地计算机的请求。
SOAP 1.1

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /ATXWebService.asmx HTTP/1.1
Host: 192.168.3.110
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "127.0.0.1/login"

<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<login xmlns="127.0.0.1">
<Password>string</Password>
</login>
</soap:Body>
</soap:Envelope>

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<loginResponse xmlns="127.0.0.1">
<loginResult>string</loginResult>
</loginResponse>
</soap:Body>
</soap:Envelope>

SOAP 1.2

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /ATXWebService.asmx HTTP/1.1
Host: 192.168.3.110
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?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:Body>
<login xmlns="127.0.0.1">
<Password>string</Password>
</login>
</soap12:Body>
</soap12:Envelope>

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?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:Body>
<loginResponse xmlns="127.0.0.1">
<loginResult>string</loginResult>
</loginResponse>
</soap12:Body>
</soap12:Envelope>

//上面这两段是从网页上直接复制出来的。

//下面的我在xcode7里面访问的代码;环境是xcode7+ios9,web调用是AFNetworking最新版的。(老版用RequestManager,新版是用AFHTTPSessionManager了),Web服务用c#2010写的,挂在IIS里面,网页访问可以访问。
// XCode代码如下:

- (void)viewDidLoad {
[super viewDidLoad];

AFHTTPSessionManager* managet=[[AFHTTPSessionManager alloc] init];

// Requests 请求Header参数
managet.requestSerializer = [AFHTTPRequestSerializer serializer];
//系统Header参数
[managet.requestSerializer setValue:@"192.168.3.110" forHTTPHeaderField:@"Host"];
[managet.requestSerializer setValue:@"application/sx-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[managet.requestSerializer setValue:@"length" forHTTPHeaderField:@"Content-length"];

//Responses 响应Header参数
managet.responseSerializer = [AFJSONResponseSerializer serializer];

managet.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/xml; charset=utf-8"];
//参数
NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init];

[parameters setObject:@"Password" forKey:@"123456"];

[managet POST:@"http://192.168.3.110/ATXWebService.asmx?op=login" parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
NSLog(@"progress");
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"SUccess%@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"Error");
}];
}

//因为是新手,我是新手,所以功能是最基本的调用。但运行后
//运行也不会报错,就是返回一直是返回failure的结果,不知道是哪里参数没对还是怎么回事。
//本来想自己处理的,昨天和今天都在网上看贴,最先看网上用IOS内建的NSURLConnection,最后发现API己经停用了,
//后来看说用ASIHTTPRequest,导入后一堆的错误,不能ARC等一直没找到原因,
//最后用AFNetworking,终于是能用了,但不会调用还是没搞定,郁郁了两天了,大神帮帮看一下。麻烦大家了,感谢!


...全文
619 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
worker-1 2016-12-07
  • 打赏
  • 举报
回复
AFHTTPSessionManager* managet=[[AFHTTPSessionManager alloc] init]; // Requests 请求Header参数 managet.requestSerializer = [AFHTTPRequestSerializer serializer]; //系统Header参数 [managet.requestSerializer setValue:@"139.129.222.77" forHTTPHeaderField:@"Host"]; [managet.requestSerializer setValue:@"application/sx-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [managet.requestSerializer setValue:@"length" forHTTPHeaderField:@"Content-length"]; //Responses 响应Header参数 managet.responseSerializer = [AFJSONResponseSerializer serializer]; managet.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/xml; charset=utf-8"]; //参数 NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init]; [parameters setObject:@"admin" forKey:@"loginName"]; [parameters setObject:@"123" forKey:@"password"]; [managet POST:@"http://139.129.222.77:8090/GasService.asmx?op=Login" parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) { NSLog(@"progress"); } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"SUccess%@",responseObject); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"Error"); NSLog(@"%@",error); }]; 这里完全是照着楼主写的
worker-1 2016-12-07
  • 打赏
  • 举报
回复
SOAP 1.1 以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。 POST /GasService.asmx HTTP/1.1 Host: 139.129.222.77 Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/Login" <?xml version="1.0" encoding="utf-8"?> <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/"> <soap:Body> <Login xmlns="http://tempuri.org/"> <loginName>string</loginName> <password>string</password> </Login> </soap:Body> </soap:Envelope> HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <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/"> <soap:Body> <LoginResponse xmlns="http://tempuri.org/"> <LoginResult>string</LoginResult> </LoginResponse> </soap:Body> </soap:Envelope> SOAP 1.2 以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。 POST /GasService.asmx HTTP/1.1 Host: 139.129.222.77 Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?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:Body> <Login xmlns="http://tempuri.org/"> <loginName>string</loginName> <password>string</password> </Login> </soap12:Body> </soap12:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?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:Body> <LoginResponse xmlns="http://tempuri.org/"> <LoginResult>string</LoginResult> </LoginResponse> </soap12:Body> </soap12:Envelope> 这里是soap
worker-1 2016-12-07
  • 打赏
  • 举报
回复
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={NSUnderlyingError=0x61000004b1c0 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/soap+xml" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x600000036860> { URL: http://139.129.222.77:8090/GasService.asmx?op=Login } { status code: 500, headers { "Cache-Control" = private; "Content-Length" = 506; "Content-Type" = "application/soap+xml; charset=utf-8"; Date = "Wed, 07 Dec 2016 08:23:37 GMT"; Server = "Microsoft-IIS/7.5"; "X-AspNet-Version" = "4.0.30319"; "X-Powered-By" = "ASP.NET"; } }, NSErrorFailingURLKey=http://139.129.222.77:8090/GasService.asmx?op=Login, com.alamofire.serialization.response.error.data=<3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d227574 662d3822 3f3e3c73 6f61703a 456e7665 6c6f7065 20786d6c 6e733a73 6f61703d 22687474 703a2f2f 7777772e 77332e6f 72672f32 3030332f 30352f73 6f61702d 656e7665 6c6f7065 2220786d 6c6e733a 7873693d 22687474 703a2f2f 7777772e 77332e6f 72672f32 3030312f 584d4c53 6368656d 612d696e 7374616e 63652220 786d6c6e 733a7873 643d2268 7474703a 2f2f7777 772e7733 2e6f7267 2f323030 312f584d 4c536368 656d6122 3e3c736f 61703a42 6f64793e 3c736f61 703a4661 756c743e 3c736f61 703a436f 64653e3c 736f6170 3a56616c 75653e73 6f61703a 52656365 69766572 3c2f736f 61703a56 616c7565 3e3c2f73 6f61703a 436f6465 3e3c736f 61703a52 6561736f 6e3e3c73 6f61703a 54657874 20786d6c 3a6c616e 673d227a 682d4348 53223ee6 9c8de58a a1e599a8 e697a0e6 b395e5a4 84e79086 e8afb7e6 b182e380 82202d2d 2d266774 3b20e6a0 b9e7baa7 e588abe4 b88ae79a 84e695b0 e68daee6 97a0e695 88e38082 20e7acac 203120e8 a18cefbc 8ce4bd8d e7bdae20 31e38082 3c2f736f 61703a54 6578743e 3c2f736f 61703a52 6561736f 6e3e3c73 6f61703a 44657461 696c202f 3e3c2f73 6f61703a 4661756c 743e3c2f 736f6170 3a426f64 793e3c2f 736f6170 3a456e76 656c6f70 653e>, NSLocalizedDescription=Request failed: unacceptable content-type: application/soap+xml}}, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x600000036860> { URL: http://139.129.222.77:8090/GasService.asmx?op=Login } { status code: 500, headers { "Cache-Control" = private; "Content-Length" = 506; "Content-Type" = "application/soap+xml; charset=utf-8"; Date = "Wed, 07 Dec 2016 08:23:37 GMT"; Server = "Microsoft-IIS/7.5"; "X-AspNet-Version" = "4.0.30319"; "X-Powered-By" = "ASP.NET"; } }, NSErrorFailingURLKey=http://139.129.222.77:8090/GasService.asmx?op=Login, com.alamofire.serialization.response.error.data=<3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d227574 662d3822 3f3e3c73 6f61703a 456e7665 6c6f7065 20786d6c 6e733a73 6f61703d 22687474 703a2f2f 7777772e 77332e6f 72672f32 3030332f 30352f73 6f61702d 656e7665 6c6f7065 2220786d 6c6e733a 7873693d 22687474 703a2f2f 7777772e 77332e6f 72672f32 3030312f 584d4c53 6368656d 612d696e 7374616e 63652220 786d6c6e 733a7873 643d2268 7474703a 2f2f7777 772e7733 2e6f7267 2f323030 312f584d 4c536368 656d6122 3e3c736f 61703a42 6f64793e 3c736f61 703a4661 756c743e 3c736f61 703a436f 64653e3c 736f6170 3a56616c 75653e73 6f61703a 52656365 69766572 3c2f736f 61703a56 616c7565 3e3c2f73 6f61703a 436f6465 3e3c736f 61703a52 6561736f 6e3e3c73 6f61703a 54657874 20786d6c 3a6c616e 673d227a 682d4348 53223ee6 9c8de58a a1e599a8 e697a0e6 b395e5a4 84e79086 e8afb7e6 b182e380 82202d2d 2d266774 3b20e6a0 b9e7baa7 e588abe4 b88ae79a 84e695b0 e68daee6 97a0e695 88e38082 20e7acac 203120e8 a18cefbc 8ce4bd8d e7bdae20 31e38082 3c2f736f 61703a54 6578743e 3c2f736f 61703a52 6561736f 6e3e3c73 6f61703a 44657461 696c202f 3e3c2f73 6f61703a 4661756c 743e3c2f 736f6170 3a426f64 793e3c2f 736f6170 3a456e76 656c6f70 653e>, NSLocalizedDescription=Request failed: internal server error (500)} 我这也是第一次整 这个错误是content-type的问题吗我这里要怎么设置
11个口袋 2016-05-27
  • 打赏
  • 举报
回复
主要是因为要做个客户端给客户手机上看公司销售情况的所以才做webservice. 没有错误,就是说运行都正常就是调用不进入success代码段里面.直接进入了failure段.
自由_ 2016-05-27
  • 打赏
  • 举报
回复
具体是什么错误了,还有就是真心不建议用WebService来用接口,用MVC不可以吗
11个口袋 2016-05-27
  • 打赏
  • 举报
回复
引用 3 楼 lluoyulin 的回复:
就是进入failure时候的错误啊,这个失败的原因是有日志出来的,你不贴出出来,怎么帮你
讲真的新手就真的是新手, 楼上一句话,真是一语惊醒梦中人。NSLOG里面可以直接显示出错的。 通过出错提示一步步,搞定了问题。我真服了我自己了,搞了两天,太冤枉了。 痛快!可以好好睡觉了。 很感谢!
自由_ 2016-05-27
  • 打赏
  • 举报
回复
就是进入failure时候的错误啊,这个失败的原因是有日志出来的,你不贴出出来,怎么帮你

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧