2 Replies Latest reply: Jul 3, 2014 10:37 PM by lazyGeek
lazyGeek Level 1 (0 points)

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

 

#import "XYZViewController.h"

@interface XYZViewController ()

@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 = [[NSMutableString alloc]init];

       

       

    }

    return self;

}

 

-(IBAction)invokeService

{

if([[UserName text] isEqualToString:@""] || [[Password text] isEqualToString:@""] ) {

       

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

        [alert show];

   }

   

    else {

 

  NSString *soapFormat = [NSString stringWithFormat:@"<?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 = [NSURL URLWithString:@"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 = [[NSMutableData alloc]init];

            startActivityIndicator;

  }

  else {

  NSLog(@"No Connection established");

  }

 

 

  }

   

}

 

 

//NSURLConnection delegate method

 

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

{

  [webData setLength: 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", [webData length]);

NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];

  NSLog(@"%@",theXML);

 

xmlParser = [[NSXMLParser alloc]initWithData:webData];

  [xmlParser setDelegate: self];

//[xmlParser setShouldResolveExternalEntities: YES];

  [xmlParser parse];

//[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

{

  [nodeContent appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

}

 

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

{

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

       

       

  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"you have entered!" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"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 {

    [super viewDidUnload];

    // Release any retained subviews of the main view.

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

}

 

-(IBAction)goAwayKeyboard:(id)sender{

   

    [sender resignFirstResponder];

}

-(IBAction)tapBackground:(id)sender{

   

    [UserName resignFirstResponder];

    [Password resignFirstResponder];

   

}

 

@end

  • Frank Caggiano Level 7 (25,715 points)

    And the error would be?? Do you expect someone to bench debug your code without having even an inkling of what is wrong?

     

    Your ASC name seems correct at least.

  • lazyGeek Level 1 (0 points)

    sir , i didnt wanna offend you with this stupid question of mine ,moreover i didnt know if noobs ask some question pros really get angry, but i am really new to this thing, *sorry*.

    theres some problem with userauthenticationresult , i am not able to connect , how to return its value !