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 02-02-2010, 11:52 AM   #2 (permalink)
tychop
N3RD
 
Join Date: Oct 2009
Posts: 201
Default

Quote:
Originally Posted by dukeatcoding View Post
Hello everybody,

Currently I am working on the problem to communicate with a WebService using Soap.

There seems to be no really stable framework coded in objective-c. So I thought about using some C++. But I wonder if its really possible to work with C++ on the Iphone because of the need C++ libs.

Has anyone other ideas for connection to a Web Service or experience in using C++ on Iphone ?
I use the iPhone SDK for webservices. I create a request like the next code fragment shows, and use NSXMLParser for parsing the response. (use NSXMLParser delegates for nested XML tags).

Code:
	NSString *path = [NSString stringWithFormat:@"*****.xml", [[NSBundle mainBundle] bundlePath]];
	NSString *nakedRequest = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
	NSString *soapMessage = [NSString stringWithFormat:nakedRequest,
							 @"user",	
							 @"pass",							
							 @"id",							
							 returnType,							
							 origin,								
							 destination,							
							 originDateString,							
							 destinationDateString,						
							 @"Timetable",							
							 @"1",									
							 @"0"									
							 ];
	
	NSURL *url = [NSURL URLWithString:@"https://services.*****.com/*****/*****.asmx"];
	NSString *messageLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
	NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];	
	[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
	[theRequest addValue:@"http://www.*****.com/*****:*****" forHTTPHeaderField:@"SOAPAction"];	
	[theRequest addValue:messageLength forHTTPHeaderField:@"Content-Length"];
	[theRequest setHTTPMethod:@"POST"];
	[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
	theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
	if (theConnection) {
		soapResponseData = [[NSMutableData data] retain];
	}
Works like a charm.
You could even opt to start parsing while the response is still loading.

Last edited by tychop; 02-02-2010 at 12:13 PM.
tychop is offline   Reply With Quote
 

» Advertisements
» Online Users: 286
17 members and 269 guests
ADY, apatsufas, chemistry, Fit4him, headkaze, ilmman, MarkC, marto1914, Meoz, PsychoChris, sly24, sneaky, Sunny46, tgjorgoski, Thrillhouse1919, timle8n1, vogueestylee
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,877
Threads: 89,222
Posts: 380,718
Top Poster: BrianSlick (7,129)
Welcome to our newest member, peterkessler45
Powered by vBadvanced CMPS v3.1.0

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