I am having trouble to upload(from Silverlight 4) a wav file to the server(WCF .NET 4). The file is uploaded from SL to server and write it to disk. But the uploaded file is changed. The two files(before uploading and the uploaded one) have exact same size but different content. And I tried the uploading in a normal console program, it works fine. It seems that the WCF has done something when serializing the data from SL. Anyone has any ideas what is going on ?
The service code is as following:
[ServiceContract(Namespace = "")]
interface ISoundService
{
[OperationContract]
int UploadSound(UploadSoundFile file);
}
public int UploadSound(UploadSoundFile file)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/" + file.FileName;
File.WriteAllBytes(path, file.File);
return 0;
}
[DataContract]
public class UploadSoundFile
{
[DataMember]
public string FileName;
[DataMember]
public byte[] File;
}
Service config is
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Service.SoundService.customBinding0" maxReceivedMessageSize="2000000" maxBufferSize="2000000">
<readerQuotas maxArrayLength="2000000" maxStringContentLength="2000000"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="Service.SoundServiceBehavior" name="Service.SoundService">
<endpoint address="" binding="basicHttpBinding" contract="Service.ISoundService" bindingConfiguration="Service.SoundService.customBinding0"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Service.SoundServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Silverlight client is:
private static int uploadSoundOnServer(string fileName, Stream stream)
{
SoundServiceClient c = new SoundServiceClient();
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, checked((int)stream.Length));
UploadSoundFile file = new UploadSoundFile() { FileName= fileName, File = buffer, };
c.UploadSoundAsync(file);
return 0;
}