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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials > Tutorial Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 12-10-2010, 01:09 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 1
satya1 is on a distinguished road
Default problem regarding webservices

i must retrieve image and two labels from soap web services but in my output either one of them are coming can any one help me my code look like this


.m file look like thisss


- (void)viewDidLoad {


recordResults = FALSE;

NSString *soapMessage = [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"
"<Get_iMagzyn_Element xmlns=\"http://www.9atoms.com/\">\n"
" <PAGE_ID>1</PAGE_ID>\n"
"</Get_iMagzyn_Element>\n"
"</soap:Body>\n"
"</soap:Envelope>\n"];
NSLog(@"soapMessage: %@", soapMessage);

NSURL *url = [NSURL URLWithString:@"http://www.9atoms.com/imagzynws/webservice.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://www.9atoms.com/Get_iMagzyn_Element" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];


if(theConnection )
{
webData = [[NSMutableData data]retain];

}
else
{
NSLog(@"theConnection is NULL");
}

ELEMENT_WIDTH=[[NSString alloc] init];
height=[[NSString alloc]init];
location1=[[NSString alloc]init];
location2=[[NSString alloc]init];
elementurl=[[NSString alloc]init];
lbl=[[NSString alloc]init];
lbl1=[[NSString alloc]init];
elementid=[[NSString alloc]init];
[super viewDidLoad];

}



-(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");
[webData release];
//[connection release];
//[webData release];
}

-(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:%@",theXML);
[theXML release];

if(xmlParser)
{
[xmlParser release];
}

xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
[webData release];
}



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

currentElement = [NSString stringWithString:elementName];
currentElement = [currentElement stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//NSLog(@"Current element = %@", currentElement);

}

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

if([currentElement isEqualToString:@"ELEMENT_WIDTH"]) {

ELEMENT_WIDTH = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

[ELEMENT_WIDTH retain];
NSLog(@"width = %@", ELEMENT_WIDTH);

}


if([currentElement isEqualToString:@"ELEMENT_HEIGHT"]) {

height = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
height = string;
[height retain];
NSLog(@"height = %@", height);

}

if([currentElement isEqualToString:@"ELEMENT_TEXT"]) {

lbl = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
lbl = string;
[lbl retain];
NSLog(@"text = %@", lbl);
}
if([currentElement isEqualToString:@"ELEMENT_TEXT"]) {

lbl1 = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
lbl1 = string;
[lbl1 retain];
NSLog(@"text1 = %@", lbl1);
}




if([currentElement isEqualToString:@"ELEMENT_LOC_X"]) {

location1= [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[location1 retain];
NSLog(@"X loc = %@", location1);


}
if([currentElement isEqualToString:@"ELEMENT_LOC_Y"])
{
location2 = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[location2 retain];
NSLog(@"y loc %@",location2);


}

if([currentElement isEqualToString:@"ELEMENT_ID"]) {

elementid= [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[elementid retain];
NSLog(@"elementid = %@", elementid);


}





if ([currentElement isEqualToString:@"ELEMENT_IMAGE_URL"]) {
elementurl=string;
elementurl= [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[elementurl retain];

}
}


-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"Get_iMagzyn_ElementResponse"]) {

recordResults = FALSE;
//NSLog(@"element name %@",elementName);
// [soapResults release];
// soapResults = nil;
}
}

-(void)parserDidEndDocument:(NSXMLParser *)parser
{


if (elementid>@"")
{
[self createImage];
[self createText];
[self createText1];
}
}


-(void)createImage
{
imageView=[[UIImageView alloc] initWithFrame:CGRectMake([location1 floatValue], [location2 floatValue], [ELEMENT_WIDTH floatValue], [height floatValue])];
//imageView=[[UIImageView alloc]initWithFrame:CGRectMake(140, 310, 200, 200)];
NSString *newURL = [@"http://" stringByAppendingString:elementurl];
NSURL *url=[NSURL URLWithString:newURL];
NSLog(@"url=%@",[url description]);
NSData *imageData=[[NSData alloc] initWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:imageData];
imageView.image = image;
//imageView.backgroundColor=[UIColor blackColor];
[self.view addSubview:imageView];
[imageView release];
[image release];
[imageData release];
}
-(void)createText
{
label=[[UILabel alloc]initWithFrame:CGRectMake([location1 floatValue],[location2 floatValue],[ELEMENT_WIDTH floatValue],[height floatValue])];
//label=[[UILabel alloc]initWithFrame:CGRectMake(101, 250, 88, 32)];
label.text=lbl;
//NSLog(@"label %@",label);
[self.view addSubview:label];
[label release];

}
-(void)createText1

{

label1=[[UILabel alloc]initWithFrame:CGRectMake([location1 floatValue],[location2 floatValue],[ELEMENT_WIDTH floatValue],[height floatValue])];
//label=[[UILabel alloc]initWithFrame:CGRectMake(101, 250, 88, 32)];
label1.text=lbl1;
//NSLog(@"label %@",label);
[self.view addSubview:label1];
[label1 release];
}

can any one help me????
satya1 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, webservices

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,961
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:56 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0