iphone - 无法从 iPhone 连接基于 soap 的 wcf 服务

标签 iphone ios soap nsmutableurlrequest

我正尝试从我的 iPhone 应用程序使用 SOAP Web 服务,但在与 Charles 核对时出现以下错误:

值不能为空。 参数名称:s

以下是我的代码:

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><updateTimesheet><TimeSheetHourID>222</TimeSheetHourID></updateTimesheet></SOAP-ENV:Body></SOAP-ENV:Envelope>"];

NSURL *url = [NSURL URLWithString:@"http://172.xx.xxx.xx:xxxx/postService.svc/basic"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];


NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
NSLog(@"Message Length..%@",msgLength);

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"urn:IpostService/updateTimesheet" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
//NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
    NSLog(@"Response: %@", result);
    //here you get the response 
}

我收到错误代码 500 作为响应。有人可以帮帮我吗?

谢谢
潘卡吉

最佳答案

错误 500 是 - 内部服务器错误。意思是 - 服务器遇到意外情况,无法满足请求。

确保您向服务器发送正确的请求。您可以在其他地方食用吗?

关于iphone - 无法从 iPhone 连接基于 soap 的 wcf 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192585/

相关文章:

iOS应用程序分配越来越多的内存

java - Apache Camel xpath 条件路由

php - 自动发现不尊重 Zend Framework 类映射?

android - 如何判断一个app是native还是html5?

iphone - 在 iOS 上,有没有办法只搜索带有特定标签的 subview ?

ios - 无法在 iPhone 上运行应用程序

iOS Push Segue(以编程方式)有时会卡住但不会崩溃

ruby - 使用 savon 的 SOAP 消息标记名称中的大小写问题

Iphone UIButton 无法在嵌套 UIView 中工作

iphone - 为什么我会在这个简单的代码上收到 Bad Access 异常?