upload XML and image on WCF server using SOAP request in iphone sdk

gulandril

New Member
I am trying to implement POST method. But my server guys not able to get image from WCF WBS.I try to use following code for that. Please anyone can help me out it that please. UIImage *myPic = [UIImage imagewithname:makeappreview.png];NSData *imageData = http://stackoverflow.com/questions/15506995/UIImagePNGRepresentation(myPic);\[code\]NSString* strValue=http://stackoverflow.com/questions/15506995/[NSString stringWithFormat:@"<UserInformation><Userid>123</Userid><FirstName>Akii</FirstName><LastName>Akii</LastName><Contact>123456</Contact><Email>[email protected]</Email><Address>India</Address><UserImg>%@</UserImg></UserInformation>",imageData];uploadValues = [uploadValues stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];NSString* soapString = [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" "%@\n" "</soap:Body>\n" "</soap:Envelope>\n",[strValue UTF8String]];NSURL *url = [NSURL URLWithString:@"http://www.makeappreview.com/test.asmx"];NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];NSString *msgLength = [NSString stringWithFormat:@"%d", [soapString length]];[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];[theRequest addValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];[theRequest addValue: @"http://www.makeappreview.com" forHTTPHeaderField:@"SOAPAction"];[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];[theRequest setHTTPMethod:@"POST"];[theRequest setHTTPBody: [soapString dataUsingEncoding:NSUTF8StringEncoding]];NSError *error = nil;NSURLResponse *response = nil;// Synchronous isn't ideal, but simplifies the code for the DemoNSData *xmlData = http://stackoverflow.com/questions/15506995/[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];NSString *returnString = [[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease];NSLog(@"returnString %@",returnString);\[/code\]
 
Back
Top