I have searched a lot on how to send an UIImageView to my WCF service from iOS, knowing that I work with xcode5.
can you please Help me to find a way to sort it out. you can find below what I did to solve the issue but I cannot solve it with it.
first I created a WCF service that accepts a string as parameter:
Serice.cvs
public string InsertNewImage(string imageEncoded) {
//I added the method to convert the imageEncoded from base64
//Then insert the image in sql server DB.
}
IService.cs:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json/InsertNewImage/{id1}")]
string InsertNewImage(string id1);
and in my iOS code, I implemented a button to call my web service as below :
//Encode my UIIMage
-(NSString *)encodeToBase64String:(UIImage *)image {
return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
//assign the Encode method result
NSString *imageStringEncoded = encodeToBase64String(myUIIMage);
NSString *str= @"http://serverIP/iOS/Service.svc/json/";
str=[str stringByAppendingFormat:@"InsertNewImage/%@" , imageStringEncoded];
str=[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *WcfSeviceURL = [NSURL URLWithString:str];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:WcfSeviceURL];
[request setHTTPMethod:@"POST"];
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
can you please help me with this approach or suggest on me another way to do that.
thank you