ios - 将图像发送到 SOAP 网络服务

标签 ios objective-c web-services

我正在尝试发送一些文本和图像。我可以发送除图像以外的所有内容。问题是我不知道如何通过它。

在 .net soap webservice 中,图像被声明为 base64binary。 objective-c 中的等价物是什么?我应该如何在 objective-c 中传递它?

这是我的代码(我正在为图像发送一个空字符串,这段代码有效但没有为图像列插入任何内容)

NSString *soapMessage = [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"
                         "<insert_data xmlns=\"http://tempuri.org/\">\n"
                         "<id>%@</id>"
                         "<name>%@</name>"
                         "<lname>%@</lname>"
                         "<date>%@</date>"
                         "<image1>%@</image1>"
                         "</insert_data>"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n",@"999",@"arif",@"yilmaz",@"2013-09-09",@""];


  (void)imagePickerController:(UIImagePickerController *)picker
 didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
 [self.popoverController dismissPopoverAnimated:true];
[popoverController release];

NSString *mediaType = [info
                       objectForKey:UIImagePickerControllerMediaType];
 [self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
    UIImage *image = [info
                      objectForKey:UIImagePickerControllerOriginalImage];

    /* Setting the images to the correct viewer - AY */
    if(image_counter==0){
        imageView.image = image;
        *datax = UIImagePNGRepresentation(image);   
        //********* I am getting the error here
        // "Assigning to 'NSData' from incompatible type NSData * "
    }
    else if(image_counter==1){
        imageView2.image = image;
    }
    else{
        imageView3.image = image;
    }
    if(image_counter<3)
        image_counter++;
    /******************/

    if (newMedia)
        UIImageWriteToSavedPhotosAlbum(image,
                                       self,
                                       @selector(image:finishedSavingWithError:contextInfo:),
                                       nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
    // Code here to support video if enabled
}

最佳答案

尝试使用这个。在这里提供您的图像并将图像的数据发送到服务器。

UIImage *img = [UIImage imageNamed:@"imageName.png"];
NSData *data = UIImagePNGRepresentation(img);

NSString *soapMessage = [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"
                         "<insert_data xmlns=\"http://tempuri.org/\">\n"
                         "<id>%@</id>"
                         "<name>%@</name>"
                         "<lname>%@</lname>"
                         "<date>%@</date>"
                         "<image1>%@</image1>"
                         "</insert_data>"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n",@"999",@"arif",@"yilmaz",@"2013-09-09",data];

已编辑......

从这里删除指针变量...

  datax = UIImagePNGRepresentation(image); 

关于ios - 将图像发送到 SOAP 网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16712641/

相关文章:

ios - UILabel 显示错误

ios - Lottie Framework 问题 - 动画无法运行

ios - cellForRowAtIndexPath 中有很多 Switch 案例

ios - 使用 TBXML 进行解析

ios - 我们可以在 NSIndexPath 对象中存储什么类型的数据

ios - 如何让循环等到 block 完成?

ios - 使用滑动手势切换 View Controller

Java rest 网络服务显示名称

php - 实时网络服务的更改和测试

javascript - 将 SignalR 与自托管 WCF 结合使用并通过 HTML 客户端使用集线器代理