Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I need to write service that Receives multiple Images using WCF.
till now i was succeed for accepting single Image , but fails on multiple images.

This service was consumed by mobile team (Android phone gap) , they are sending Image as Base64string.


C#
[DataContract]
 public class multipleImageClass
 {
     [DataMember]
     public string base64String;

     [DataMember]
     public string image;
 }

 [OperationContract]
     [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetMultipleImages")]
     string GetMultipleImages(List<multipleImageClass> obj);



  public string GetMultipleImages(List<multipleImageClass> obj)
     {

             var count = obj.Count();

             if (count > 0)
             {

                 foreach (var items in obj)
                 {

                     byte[] bytes = Convert.FromBase64String(items.base64String);

                     MemoryStream ms = new MemoryStream(bytes);

                    // Doing my work here after converting base64string to Memory Stream

                 }

     }



above code is working fine for single Image.Service end point is not triggering , if we send base64string multiple images. may be the reason is Base64string.

what is the best way for sending multiple using WCF Service ? I am using Visual studio 2010, C# 4.0
Posted
Comments
RaisKazi 20-Dec-14 23:03pm    
As an alternate option you may consider using NodeJs-Express. Just as suggestion.
Raul Iloc 30-Dec-14 10:53am    
Did you try it like I indicated in my solution below?
dorababu407 30-Dec-14 11:13am    
i tried previously by passing multiple images as array of objects but not as output parameter. i tried this solution before i posted question here but not succeed.
Raul Iloc 30-Dec-14 11:29am    
You should check all 4 points from my solution, and 1st point said that you have to use array and not "List".
dorababu407 30-Dec-14 11:42am    
i used array objects only, but not as output parameter

1 solution

Here are my recommendations:
1.For each image the image data should be sent as bytes array (byte[] imageData;).

2. Because an image could be a large file it is commanded to transfer only one image at a time and not a list of images.

3. If you really want to transfer multiple images in one single call your method signature from your WCF service, you class name should be MultipleImageClass, then the images data should be an array of objects and not a list, this images data should be returned as out parameter, and the method should return an error code like below:
C#
public int GetMultipleImages(out MultipleImageClass[] myImages)
{
//...
//
return 0; //Success!
}

4.You should have a look also on my next answer related with WCF service configuration issue: How to transfer same class obj that was received from WCF service to Application C#[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900