Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 807223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:22:15+00:00 2026-05-15T00:22:15+00:00

I worked on this for several hours today and I’m pretty close to a

  • 0

I worked on this for several hours today and I’m pretty close to a solution but clearly need some help from someone who’s pulled this off. I’m trying to post an image to a web service from the iPhone. I’ll post the code first then explain everything I’ve tried:

NSData *imageData = UIImageJPEGRepresentation(barCodePic, .9);


NSString *soapMsg = 
[NSString stringWithFormat:
 @"<?xml version=\"1.0\" encoding=\"utf-8\"?><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/\"><soap:Body><WriteImage xmlns=\"http://myserver/imagewebservice/\"><ImgIn>%@</ImgIn></WriteImage></soap:Body></soap:Envelope>",  [NSData dataWithData:imageData]
 ];


NSURL *url = [NSURL URLWithString:@"http://myserver/imagewebservice/service1.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = 
[NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://myserver/imagewebservice/WriteImage" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
    webData = [[NSMutableData data] retain];
}    

First thing, this code works fine for anything but an image. The web service is running on my local network and I can change the source code at will and if I change the “ImgIn” parameter to a string and pass a string in, everything works fine, I get a return value no problem. So there are no connectivity issues at all, I’m able to call and get data from this web service on this server no problems. But I need to upload an image to this web service via the ImgIn parameter, so the above code is my best shot so far. I also have didReceiveResponse, didReceiveData, didFailWithError, etc all being handled. The above code fires off didRecieveResponse every time. However didReceiveData is never fired and it’s like the web service itself never even runs. When I debug the web service itself, it runs and debugs fine when I use a string parameter, but with the image parameter, it never even debugs when I call it. It’s almost like the ImgIn parameter is too long (it’s huge when I output it to the screen) and the web service just chokes on it. I’ve read about having to encode to Base64 when using this method, but I can’t find any good links on how that’s done. If that’s what I’m doing wrong, can you PLEASE provide code as to how to do this, not just “you need to use Base64”, I’d really appreciate it as I can find almost nothing on how to implement this with an example. Other than that, I’m kind of lost, it seems like I’m doing everything else right. Please help!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:22:16+00:00Added an answer on May 15, 2026 at 12:22 am

    It fails because the %@ format specifier takes an object and calls -(NSString*)description to turn it into a string. -[NSData description] returns something like @”<31 32 33 65 66 67>” for (ASCII) “123abc”, hence you’re submitting <31 32 33 65 66 67> which obviously isn’t valid XML. Don’t glue strings together (it’ll be vulnerable to XML injection, among other things).

    I would drop SOAP and just use

    [req addValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
    [req setHTTPBody:imgData]
    

    If you want to use SOAP, then there’s probably an Objective-C SOAP library which will do packaging for you. Failing that, you can manually specify xs:base64Binary (I think) and use base64-encoded data. Neither of these is ideal, since it makes the data 33% larger. If you’re unlucky, a SOAP library will make it 20000% larger!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I successfully installed the latest QuantumGrid from DevExpress, but I've never worked with this
At the beginning this worked fine: $ rake cucumber:all But then $ script/plugin install
This all worked fine in rails 2.3.5, but when a contractor firm upgraded directly
I've read several responses to this that I need to copy the app.config of
can you please provide some help, this is my code: <!DOCTYPE html> <html lang=en>
I haven't quite worked this one out yet - how do I set DEBUG
I have worked on this problem for my entire day and can't solve it.
I have come across Evernote's bookmarklet and was wondering how this worked. You can
I tried to compile Qt+Webkit statically with MS VS 2008 and this worked. C:\Qt\4.6.2>configure
I'm trying to use depedency resolver inside a Web Api method. This worked fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.