【发布时间】:2014-03-14 17:28:42
【问题描述】:
我已经搜索了很多关于如何从 iOS 向我的 WCF 服务发送 UIImageView 的信息,知道我使用的是 xcode5。
你能帮我想办法解决它吗?您可以在下面找到我为解决问题所做的工作,但我无法用它来解决。
首先我创建了一个接受字符串作为参数的 WCF 服务:
服务.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);
在我的 iOS 代码中,我实现了一个按钮来调用我的网络服务,如下所示:
//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];
你能帮我用这种方法还是建议我用另一种方法来做到这一点。
谢谢
【问题讨论】:
-
我不知道这个问题的解决方案,但是你的 http url 不应该超过 2000 个字符。 stackoverflow.com/questions/417142/…
-
好的,感谢您提供的信息,请问如何发送图片?
标签: ios objective-c wcf uiimageview xcode5