I am using Soap Web services and get response in XML and that Response i am store in NSMutableData and than i perform XML parsing i am using NSXMLParser. my problem is that some times it is works and some times not i can’t determine what is the problem so anybody can help me to out of this problem.
I am using this code-
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://MYLINK......." forHTTPHeaderField:@"MY_action"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData_msg = [[NSMutableData data] retain];
}
and getting also response in-
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData_msg appendData:data];
}
but after getting response parse the xml here-
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if( xmlParser_msg)
{
[xmlParser_msg release];
xmlParser_msg=nil;
}
xmlParser_msg = [[NSXMLParser alloc] initWithData: webData_msg];
[xmlParser_msg setDelegate: self];
[xmlParser_msg setShouldResolveExternalEntities: YES];
[xmlParser_msg parse];
[connection release];
[webData_msg release];
}
than problem arise here, some times NSXMLParserDelegate methods call some times not call.
What is going wrong here? please help and sorry for any mistake in English.
The problem was I was getting HTML response through web service so xml purser hangs on that.
It was sometimes errors coming from web service side with HTML content.