当我想使用我的Web服务时发生运行时错误

时间:2012-09-15 11:58:11

标签: iphone objective-c xcode web-services ios4

我在我的网站的服务器www.example.com/webservice/SampleService.asmx上传了一个Web服务,我要连接到它的方法是GetAllUserInfo,我使用下面的代码来使用这个Web服务但是发生了运行时错误,任何人都可以帮助我使用这个Web服务

  • 我测试此网络服务并在visual studio上正常工作
NSString *soapMsg =[NSString stringWithFormat:@"<?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>"     
 "<GetAllUserInfo xmlns=\"http://www.example.com/\">" 
 "</GetAllUserInfo>"   
 "</soap:Body>"    
 "</soap:Envelope>"];

NSURL *url = [NSURL URLWithString:@"http://www.example.com/SampleService.asmx"];              

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];                  
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];               
[req addValue:@"http://www.example.com/GetAllUserInfo" forHTTPHeaderField:@"SOAPAction"];

[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];          
[req setHTTPMethod:@"POST"];                
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

1 个答案:

答案 0 :(得分:1)

您可以使用以下命令获取完整的错误消息:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"data: %.*s", [data length], [data bytes]);
}