Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-30-2008, 02:14 AM   #27 (permalink)
Black Scyther
Registered Member
 
Join Date: Sep 2008
Posts: 36
Default

I tried to establish a connection with a request:
Code:
- (NSMutableData *)createRequest:(NSString *)city {
	NSMutableData *myMutableData;
	NSMutableString *sRequest = [[NSMutableString alloc] init];
	[sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
	[sRequest appendString:@"<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/\">"];
	[sRequest appendString:@"<soap:Body>"];
    [sRequest appendString:@"<GetWeather xmlns=\"http://litwinconsulting.com/webservices/\">"];
	[sRequest appendString:@"<City>"];
	[sRequest appendString:city];
	[sRequest appendString:@"</City>"];
    [sRequest appendString:@"</GetWeather>"];
	[sRequest appendString:@"</soap:Body>"];
	[sRequest appendString:@"</soap:Envelope>"];
	
	NSURL *weatherServiceURL = [NSURL URLWithString:@"http://litwinconsulting.com/webservices/GetWeather"];
	
	NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:weatherServiceURL];
	 
	 [request addValue:@"text/xml; charset:UTF-8" forHTTPHeaderField:@"Content-Type"];
	 [request addValue:@"http://litwinconsulting.com/webservices/GetWeather" forHTTPHeaderField:@"SOAPAction"]; 
	
	 [request setHTTPMethod:@"POST"];
	 
	 [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
	
	NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
	 
	if (conn) {
		myMutableData = [[NSMutableData data] retain];
		//NSLog(@"Conn is true");
	}
	[NSURLConnection connectionWithRequest:request delegate:self];
	
	NSError *WSerror;
	NSURLResponse *WSresponse;
	
	myMutableData = [NSURLConnection sendSynchronousRequest:request
					  returningResponse:&WSresponse error:&WSerror];


	return myMutableData;
	
}
and tried to parse the result:

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	
	[myText setText:@"0"];
	
    // Uncomment the following line to add the Edit button to the navigation bar.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
	SOAPRequest *request = [[SOAPRequest alloc] init];
	
	NSData *myData = [[NSData alloc] initWithData:[request createRequest:@"Vienna"]];
	
	NSXMLParser *parser = [[NSXMLParser alloc] initWithData:myData];
	[parser setShouldProcessNamespaces:NO];
	[parser setShouldReportNamespacePrefixes:NO];
	[parser setShouldResolveExternalEntities:NO];
	
	[parser parse];
	
	[parser release];
	
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributDict {
	NSLog(@"Found element %@", elementName);
	
	if ([elementName isEqualToString:@"GetWeatherResult"]) {
		[myText setText:elementName];
	}
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
	[myText setText:string];
}		
		
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
 qualifiedName:(NSString *)qName {
	
}

Im not sure if i use the parser correct but the 3 parser methods are never called either.

Any idea?
Black Scyther is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,870
Threads: 89,225
Posts: 380,694
Top Poster: BrianSlick (7,129)
Welcome to our newest member, triclopus
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:45 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.