Monday, August 27, 2012

Passing image in Silverlight 4 WCF changes the size to 1K

Passing image in Silverlight 4 WCF changes the size to 1K

I have all the sizes maxed out and not sure why the image (any) gets saved as a 1K unreadable image.
web config
<bindings>           <basicHttpBinding>             <!-- Create a custom binding for our service to enable sending large amount of data -->             <binding name="mywebsite.wcfDataLayer.basicHttpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"                      maxBufferSize="2147483647">               <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />             </binding>           </basicHttpBinding>         </bindings>               <serviceHostingEnvironment aspNetCompatibilityEnabled="true"               multipleSiteBindingsEnabled="true" />           <services>               <service name="mywebsite.wcfDataLayer">                   <endpoint name="occ" address="" binding="basicHttpBinding" bindingConfiguration="mywebsite.wcfDataLayer.basicHttpBinding"                       contract="mywebsite.wcfDataLayer" />                   <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />               </service>  .  .  .
code to save file
Dim fs As FileStream = Nothing Dim writer As BinaryWriter = Nothing
 
If image.ImageName <> String.Empty Then
    fs
= File.Open(strFilePath + image.ImageName, FileMode.Create)
    writer
= New BinaryWriter(fs)
    writer
.Write(image.ImageName)
 
End If

Answers & Comments...

Answer: 1
I'm confused.  You're writing the name of the image (a string) to a file, not the bytes of an image.


Answer: 2
That makes 2 of us.  What should it be?


Answer: 3
I realized when you typed that what I had done.  Changed to
writer.Write(image.Imagestream)
and it worked.


Answer: 4
sometimes a second pair of eyes is all you need :)  glad you got it working.




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog