Skip navigation

didReceiveData not getting called for consuming a SOAP webservice

463 Views 0 Replies Latest reply: Apr 6, 2012 4:12 PM by vvgala RSS
vvgala Calculating status...
Currently Being Moderated
Apr 6, 2012 4:12 PM

I am trying to access a webservice in iphone. didReceiveResponse connectionDidFinishLoading is getting called however didReceiveData is not getting called. I checked NSHTTPURLResponse allHeaderFields where Content-length is 0 and statusCode is 400. I am not getting why I am getting this HTTP status code. Can someone please help me in finding this error. Here is my code:


- (IBAction)buttonClickedid)sender {
NSString *soapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xlmns:soap=\"\">\n"
"<GetAllCarsJson xmlns=\"\">\n"

//---print it to the Debugger Console for verification---
*url = [NSURL URLWithString:@""];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

//---set the headers---
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];

//---set the HTTP method and body---
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

//[activityIndicator startAnimating];
= [[NSURLConnection alloc] initWithRequest:req delegate:self];
[conn start];


NSLog(@"Connection = %@", conn);
if (conn)
//webData = [[NSMutableData data] ];
= [[NSMutableData alloc] initWithCapacity:2048];
//[[NSMutableData data] retainArguments];

- (void) connection NSURLConnection *) connection didReceiveResponse NSURLResponse *)response
NSLog(@"soapMsg1: %d", [webData length]);
//webData = [[NSMutableData alloc] initWith:
[webData setLength:0];

- (void) connection NSURLConnection *) connection didReceiveData NSData *)data
[webData appendData:data];


- (void) connection NSURLConnection *) connection didFailWithError NSError *)error
//[webData release];
//[connection release];


- (void) connectionDidFinishLoading NSURLConnection *) connection
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes:[webData mutableBytes] length:             [webData length] encoding:NSUTF8StringEncoding];

//shows the XML
//[theXML release];
//[activityIndicator stopAnimating];
//[connection release];
= nil;



More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.