Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

getting xml webservices using soap on xcode

there is some error in the code , i dont know how to correct it !! *frustated*


#import "XYZViewController.h"

@interfaceXYZViewController ()

@end



@implementation XYZViewController

@synthesize UserName,Password;


#define startActivityIndicator [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES]

#define stopActivityIndicator [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];



// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {

// Custom initialization


nodeContent = [[NSMutableStringalloc]init];

}

returnself;

}


-(IBAction)invokeService

{

if([[UserNametext] isEqualToString:@""] || [[Passwordtext] isEqualToString:@""] ) {

UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"WebService"message:@"Supply Data in UserName or Password field"delegate:nilcancelButtonTitle:nilotherButtonTitles:@"ok",nil];

[alert show];

}

else {



NSString *soapFormat = [NSStringstringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"


"<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/\">\n"


"<soap:Body>\n"

"<UserAuthentication xmlns=\"http://tempuri.org/\">\n"

"<UserName>%@</UserName>"

"<Password>%@</Password>"

"</UserAuthentication>"

"</soap:Body>"

"</soap:Envelope>", UserName, Password];




NSLog(@"The request format is %@",soapFormat);



NSURL *locationOfWebService = [NSURLURLWithString:@"http://10.146.89.22/userauth/Service.asmx"];


NSLog(@"web url = %@",locationOfWebService);


NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService];


NSString *msgLength = [NSString stringWithFormat:@"%d",[soapFormat length]];


[theRequest addValue:@"text/xml"forHTTPHeaderField:@"Content-Type"];

[theRequest addValue:@"http://tempuri.org/UserAuthentication"forHTTPHeaderField:@"SOAPAction"];

[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];

[theRequest setHTTPMethod:@"POST"];

[theRequest setHTTPBody: [soapFormat dataUsingEncoding:NSUTF8StringEncoding]];


//the below encoding is used to send data over the net

[theRequest setHTTPBody:[soapFormat dataUsingEncoding:NSUTF8StringEncoding]];



NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];


if (connect) {


webData = [[NSMutableDataalloc]init];

startActivityIndicator;

}

else {


NSLog(@"No Connection established");

}



}

}



//NSURLConnection delegate method


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

{

[webDatasetLength: 0];

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{

[webData appendData:data];

}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

{

NSLog(@"ERROR with theConenction");


}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

{

NSLog(@"DONE. Received Bytes: %d", [webDatalength]);

NSString *theXML = [[NSStringalloc] initWithBytes: [webDatamutableBytes] length:[webDatalength] encoding:NSUTF8StringEncoding];

NSLog(@"%@",theXML);


xmlParser = [[NSXMLParseralloc]initWithData:webData];

[xmlParsersetDelegate: self];

//[xmlParser setShouldResolveExternalEntities: YES];

[xmlParserparse];

//[webData release];

//[resultTable reloadData];

stopActivityIndicator;

}



//xml delegates


- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict

{


}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

{

[nodeContentappendString:[string stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]]];

}


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName

{

if ([elementName isEqualToString:@"UserAuthenticationResult"]) {


UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"Message"message:@"you have entered!"delegate:nilcancelButtonTitle:nilotherButtonTitles:@"ok",nil];

[alert show];


}/*else {

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"you have not entered!" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"ok",nil];

[alert show];


}*/


}


- (void)viewDidUnload {

[superviewDidUnload];

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}


-(IBAction)goAwayKeyboard:(id)sender{

[sender resignFirstResponder];

}

-(IBAction)tapBackground:(id)sender{

[UserNameresignFirstResponder];

[PasswordresignFirstResponder];

}


@end

Posted on Jul 3, 2014 2:59 AM

Reply
2 replies

getting xml webservices using soap on xcode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.