0

I'm trying to send a picture from my Windows Phone to a WCF service, which needs a System.Drawing.Bitmap. I however, am not able to take the BitmapImage from my phone, and get a Bitmap on the WCF service. I'm doing this in C#.

I've tried making the BitmapImage into a byte[], sending it over the WCF, and converting it back to a BitmapImage, and then converting that to a Bitmap. I can get the size of the BitmapImage, but the data in the image is empty. Any clues to what could go wrong?

How do I do this?

  • There seems to be a problem during serialization and deserialization of bitmap over the wire. I would suggest you to try a different format image and see if it works. Try a jpg – Rajesh Jul 09 '12 at 11:40
  • So how would I send a jpg? - Serialize the filestream? And how do i deserialize it on the other end, so I can get a bitmap in the end? – Indifference Jul 09 '12 at 22:33
  • Is it a SOAP based service or REST? – Rajesh Jul 10 '12 at 08:46
  • I'm using the normal basicHttpBinding, so I guess I'm using SOAP. When I send a picture from a normal WPF client, it works fine, though this client does not use BitmapImage, but just Bitmap. – Indifference Jul 10 '12 at 10:23
  • Since you are using SOAP i dont think there should be any problem sending the byte array across. Worth checking your code to make sure you are missing something. Also you might want to have a look at http://stackoverflow.com/questions/4732807/conversion-of-bitmapimage-to-byte-array – Rajesh Jul 10 '12 at 11:29
  • There might be a fault, when I try to get the image back from the binary. Can you see any faults in this? `public Bitmap BinaryToBitmapImage(byte[] binary) { if (binary == null || binary.Length == 0) return null; var mem = new MemoryStream(binary); JpegBitmapDecoder decoder = new JpegBitmapDecoder(mem, BitmapCreateOptions.None, BitmapCacheOption.None); BitmapSource bitmapSource = decoder.Frames[0]; Image img = Image.FromStream(mem); Bitmap bi = new Bitmap(img); return bi; }` – Indifference Jul 10 '12 at 12:54

1 Answers1

1

The problem probably is with the maxReceivedMessageSize. You said that you can get the size of the BitmapImage but is it the correct size? If not then add the following line in your WCF's web.config:

<bindings>
  <wsHttpBinding>
    <binding name="wsHttp"
                 maxReceivedMessageSize ="50000000"
                 messageEncoding="Mtom"
                 maxBufferPoolSize="50000000" >
      <readerQuotas maxDepth="32"
         maxStringContentLength="2147483647"
         maxArrayLength="2147483647"
         maxBytesPerRead="8192"
         maxNameTableCharCount="2147483647" />
    </binding>
  </wsHttpBinding>
</bindings>

Now try again, it should work now.

naqvitalha
  • 793
  • 5
  • 9
  • I'm using basicHttpBinding, since WP7 doesn't support wsHttpBinding, and yes. The byte array is of the same size as the on the phone. It seems like I'm missing the underlying stream from the phone, though I do not know how to get this stream. Besides, I've already increased those numbers on the WCF's web.config, so I don't think thats the problem. – Indifference Jul 09 '12 at 17:07