This question is locked. New answers and comments are not allowed.
Hi there,
In my silverlight application I need download some files with more than 50 MB.
I create a webService to do that, here are the code that call the webService:
BasicHttpBinding bind = new BasicHttpBinding();
EndpointAddress endpoint = new EndpointAddress("../WebServ/webServiceSGA.asmx");
bind.MaxBufferSize = 2147483647;
bind.MaxReceivedMessageSize = 2147483647;
client.downloadDocumentoReuniaoCompleted += new EventHandler<servicoWebSGA.downloadDocumentoReuniaoCompletedEventArgs>(client_downloadDocumentoReuniaoCompleted);
client.downloadDocumentoReuniaoAsync(AppGlobais.Globais.reuniaoGlobal.IdProp.ToString(),
DocumentoReuniaoSeleccionado.UrlFicheiroProp, (int)DocumentoReuniaoSeleccionado.VersaoDocumentoProp, AppGlobais.Globais.configuracaCaminhoDocumentos.CaminhoDocumentos);
And here are the code of webService:
[WebMethod]
public byte[] downloadDocumentoReuniao(string reuniaoID, string nomeFicheiro, int versaoDocumento,string caminho)
{
string ficheiroPath;
string erro = "";
StringBuilder sb = new StringBuilder();
erro = "INICIO: ";
sb.Append(erro);
try
{
string caminhoPastaReunioes = caminho;
string caminhoFicheiro = caminhoPastaReunioes + "reuniao_" + reuniaoID + "\\documentosReuniao\\";
string caminhoFicheiroComVersao = caminhoFicheiro + Util.DevolveNomeFicheiroComVersao(nomeFicheiro, versaoDocumento, 2);
if (File.Exists(caminhoFicheiroComVersao))
{
byte[] dmp = LeFicheiro(caminhoFicheiroComVersao);
erro = "tamanho: " + dmp.Length.ToString();
sb.Append(erro);
using (StreamWriter outfile = new StreamWriter(Util.DevolvePathRaizAplicacao() + "\\Reunioes\\Log_downloadFicheiroWS.txt"))
{
outfile.WriteLine(sb.ToString());
outfile.Close();
}
return dmp;
}
else
{
erro = "Erro a ler ficheiro";
sb.Append(erro);
using (StreamWriter outfile = new StreamWriter(Util.DevolvePathRaizAplicacao() + "\\Reunioes\\Log_downloadFicheiroWS.txt"))
{
outfile.WriteLine(sb.ToString());
outfile.Close();
}
return null;
}
}
catch (Exception Erro)
{
erro = "CATCH: " + Erro.Message;
sb.Append(erro);
using (StreamWriter outfile = new StreamWriter(Util.DevolvePathRaizAplicacao() + "\\Reunioes\\Log_downloadFicheiroWSCatch.txt"))
{
outfile.WriteLine(sb.ToString());
outfile.Close();
}
throw Erro;
return null;
}
}
And here are the callBack method that will receive the byte[] from webService:
void client_downloadDocumentoReuniaoCompleted(object sender, servicoWebSGA.downloadDocumentoReuniaoCompletedEventArgs e)
{
try
{
if (e.Result != null)
{
MessageBox.Show("Audio completo\n" + e.Result.Length.ToString());
try
{
Stream audio = new MemoryStream(e.Result);
MediaEl.SetSource(audio);
this.MediaEl.Play();
}
catch (Exception ex)
{ MessageBox.Show("Ocorreu um erro com o ficheiro de áudio."); }
}
else
{
MessageBox.Show("Não foi possível fazer download do ficheiro de áudio.");
}
}
catch(Exception ex)
{
MessageBox.Show("Ocorreu um erro no callback do método descarregarGravacao\n" + ex.Message + "\n" + ex.StackTrace);
}
}
And the problem occures here, in this catch with this message:
an exception occurred during the operation, making the result invalid. Check InnerException for exception details.
ErrorCallStack:
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
To check what occure in server side, I create a simple log file, to see if the webService can open and read the file, and yes. No problem in server side, however, when goes to callBack give me that error.
I tried search about it with no luck. I read that maybe server has a restriction of response size I don´t know...
Here are my web.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ReportServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="SGA.Web.Service.DownloadFileBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="ReportServiceBehavior" name="Telerik.Reporting.Service.ReportService">
<endpoint address="" binding="basicHttpBinding" contract="Telerik.Reporting.Service.IReportService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="resources" behaviorConfiguration="WebBehavior"
binding="webHttpBinding" contract="Telerik.Reporting.Service.IResourceService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
Another thing, this problem only happen after deploy the application. If I try download in localhost works fine, but if I deploy in other machine -- ERROR.
Can you give me some clue about it?
Thanks in advance,
In my silverlight application I need download some files with more than 50 MB.
I create a webService to do that, here are the code that call the webService:
BasicHttpBinding bind = new BasicHttpBinding();
EndpointAddress endpoint = new EndpointAddress("../WebServ/webServiceSGA.asmx");
bind.MaxBufferSize = 2147483647;
bind.MaxReceivedMessageSize = 2147483647;
client.downloadDocumentoReuniaoCompleted += new EventHandler<servicoWebSGA.downloadDocumentoReuniaoCompletedEventArgs>(client_downloadDocumentoReuniaoCompleted);
client.downloadDocumentoReuniaoAsync(AppGlobais.Globais.reuniaoGlobal.IdProp.ToString(),
DocumentoReuniaoSeleccionado.UrlFicheiroProp, (int)DocumentoReuniaoSeleccionado.VersaoDocumentoProp, AppGlobais.Globais.configuracaCaminhoDocumentos.CaminhoDocumentos);
And here are the code of webService:
[WebMethod]
public byte[] downloadDocumentoReuniao(string reuniaoID, string nomeFicheiro, int versaoDocumento,string caminho)
{
string ficheiroPath;
string erro = "";
StringBuilder sb = new StringBuilder();
erro = "INICIO: ";
sb.Append(erro);
try
{
string caminhoPastaReunioes = caminho;
string caminhoFicheiro = caminhoPastaReunioes + "reuniao_" + reuniaoID + "\\documentosReuniao\\";
string caminhoFicheiroComVersao = caminhoFicheiro + Util.DevolveNomeFicheiroComVersao(nomeFicheiro, versaoDocumento, 2);
if (File.Exists(caminhoFicheiroComVersao))
{
byte[] dmp = LeFicheiro(caminhoFicheiroComVersao);
erro = "tamanho: " + dmp.Length.ToString();
sb.Append(erro);
using (StreamWriter outfile = new StreamWriter(Util.DevolvePathRaizAplicacao() + "\\Reunioes\\Log_downloadFicheiroWS.txt"))
{
outfile.WriteLine(sb.ToString());
outfile.Close();
}
return dmp;
}
else
{
erro = "Erro a ler ficheiro";
sb.Append(erro);
using (StreamWriter outfile = new StreamWriter(Util.DevolvePathRaizAplicacao() + "\\Reunioes\\Log_downloadFicheiroWS.txt"))
{
outfile.WriteLine(sb.ToString());
outfile.Close();
}
return null;
}
}
catch (Exception Erro)
{
erro = "CATCH: " + Erro.Message;
sb.Append(erro);
using (StreamWriter outfile = new StreamWriter(Util.DevolvePathRaizAplicacao() + "\\Reunioes\\Log_downloadFicheiroWSCatch.txt"))
{
outfile.WriteLine(sb.ToString());
outfile.Close();
}
throw Erro;
return null;
}
}
And here are the callBack method that will receive the byte[] from webService:
void client_downloadDocumentoReuniaoCompleted(object sender, servicoWebSGA.downloadDocumentoReuniaoCompletedEventArgs e)
{
try
{
if (e.Result != null)
{
MessageBox.Show("Audio completo\n" + e.Result.Length.ToString());
try
{
Stream audio = new MemoryStream(e.Result);
MediaEl.SetSource(audio);
this.MediaEl.Play();
}
catch (Exception ex)
{ MessageBox.Show("Ocorreu um erro com o ficheiro de áudio."); }
}
else
{
MessageBox.Show("Não foi possível fazer download do ficheiro de áudio.");
}
}
catch(Exception ex)
{
MessageBox.Show("Ocorreu um erro no callback do método descarregarGravacao\n" + ex.Message + "\n" + ex.StackTrace);
}
}
And the problem occures here, in this catch with this message:
an exception occurred during the operation, making the result invalid. Check InnerException for exception details.
ErrorCallStack:
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
To check what occure in server side, I create a simple log file, to see if the webService can open and read the file, and yes. No problem in server side, however, when goes to callBack give me that error.
I tried search about it with no luck. I read that maybe server has a restriction of response size I don´t know...
Here are my web.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ReportServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="SGA.Web.Service.DownloadFileBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="ReportServiceBehavior" name="Telerik.Reporting.Service.ReportService">
<endpoint address="" binding="basicHttpBinding" contract="Telerik.Reporting.Service.IReportService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="resources" behaviorConfiguration="WebBehavior"
binding="webHttpBinding" contract="Telerik.Reporting.Service.IResourceService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
Another thing, this problem only happen after deploy the application. If I try download in localhost works fine, but if I deploy in other machine -- ERROR.
Can you give me some clue about it?
Thanks in advance,