views:

265

answers:

2

Hi all,

I am working on an image upload from iphone to an C# web service. Here is the iPhone code

NSString *soapMessage=[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/\"&gt;\n"
        "<soap:Body>\n"
        "<PutImage xmlns=\"http://tempuri.org/\"&gt;\n"
        "<ImgInputString>%@</ImgInputString>\n"
        "</PutImage>\n"
        "</soap:Body>\n"
"</soap:Envelope>\n",imageString];

NSLog(soapMessage);
NSURL *url=[NSURL URLWithString:@"http://192.168.2.7/ImageWebService/Service1.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://tempuri.org/PutImage" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

But when i am accessing the server I am getting this error message. But when i copy and paste the image string in the webservice directly I get the image. It's only from the iPhone it is throwing the error.

Please help

A: 

I've had trouble with this too, I believe it was the encoding, (MS server specific?) here's what I would suggest.

 [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];
NWCoder
A: 

I got this solved. I had changed my server side input to be string( a bas64 string), but the web service i was hitting was not the updated one, was the previous byte[] input. So, i hanged the dll of my web service in the inetpub/wwwroot/bin to the new chnaged web service .dll. Now it works like a charm.

And NWCoder, you can encrypt your string to base64 encoding and send it as a string to your c# web serice and then convert i into a byte[]. This was smooth for me. Any ways thsnks for your suggestion.

jacob