PDA

View Full Version : [CLOSED] Dowload file with WebService...



supera
Jul 06, 2012, 6:55 PM
Hi!

I'm trying make a download file (from Database) function with a webService...
I call this webService with the Ext.net.directRequest... but I get error when httpresponse with file is returned

1 - Calling the webservice function:



Ext.net.directRequest({
url: "/App/MZWORDD/MZWORDD.asmx/DownloadFileAjax",
json: true,
cleanRequest: true,
extraParams: {
pID: wnd.objDAL.ID
}
});


The WebService:


<WebMethod(enableSession:=True)> _
<ScriptMethod()> _
Public Sub DownloadFileAjax(pID As Long)
Dim Doc As SuperaWeb.DataAccess.DocumentosMZWORDD_DAL
Dim tmpFile As Byte()

'here, I read the image from my Database
Doc = SuperaWeb.DataAccess.DocumentosMZWORDD_DAL.Get_(Co nvert.ToInt64(pID))
tmpFile = Doc.ReadBinnary()

If Not tmpFile Is Nothing Then
With HttpContext.Current.Response
.Clear()
.AddHeader("Content-Disposition", "attachment; filename=" & Doc.FileName)
.AddHeader("Content-Length", tmpFile.Length.ToString())
.ContentType = "application/octet-stream"
'.BinaryWrite(tmpFile)
.OutputStream.Write(tmpFile, 0, tmpFile.Length)
.Flush()
.End()
End With
End If
End Sub


The error: In msgBox are write:
Run time error in Microsoft JScript: Unable to complete operation
Error: c00ce514
4451

supera
Jul 06, 2012, 6:58 PM
In time!

If I call directly in the browser my WebService, works very fine!

Thanks for any help!

Daniil
Jul 08, 2012, 8:47 PM
Hi,

I think you should correct the directRequest config.

1. Remove

json: true

2. Add

isUpload: true,
formId: "form1" //AJAX downloading requires a <form>

supera
Jul 09, 2012, 11:59 AM
Hi Daniil!

I'm doing some wrong...

I changed my source code as you sugested...



Ext.net.directRequest({
url: "/App/MZWORDD/MZWORDD.asmx/DownloadFileAjax",
// json: true,
isUpload: true,
formId: "form1",
cleanRequest: true,
extraParams: {
pID: wnd.objDAL.ID
}
});


And now I'm get this error message:

Title of window error: BAD RESPONSE: Sintaxe error

Error:
System.InvalidOperationException: To be XML serializable, types which inherit from ICollection must have an implementation of Add (System.Object) levels of their inheritance hierarchy. Microsoft.VisualBasic.Collection does not implement Add (System.Object). in System.Xml.Serialization

Follow the original erro message:


System.InvalidOperationException: Para ser serializ&#225;vel por XML, tipos que herdam de ICollection devem ter uma implementa&#231;&#227;o de Add(System.Object) nos n&#237;veis de sua hierarquia de heran&#231;a. Microsoft.VisualBasic.Collection n&#227;o implementa Add(System.Object).
em System.Xml.Serialization.TypeScope.GetDefaultIndex er(Type type, String memberInfo)
em System.Xml.Serialization.TypeScope.ImportTypeDesc( Type type, MemberInfo memberInfo, Boolean directReference)
em System.Xml.Serialization.TypeScope.GetTypeDesc(Typ e type, MemberInfo source, Boolean directReference, Boolean throwOnError)
em System.Xml.Serialization.ModelScope.GetTypeModel(T ype type, Boolean directReference)
em System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
em System.Web.Services.Protocols.XmlReturn.GetInitial izers(LogicalMethodInfo[] methodInfos)
em System.Web.Services.Protocols.XmlReturnWriter.GetI nitializers(LogicalMethodInfo[] methodInfos)
em System.Web.Services.Protocols.MimeFormatter.GetIni tializers(Type type, LogicalMethodInfo[] methodInfos)
em System.Web.Services.Protocols.HttpServerType..ctor (Type type)
em System.Web.Services.Protocols.HttpServerProtocol.I nitialize()
em System.Web.Services.Protocols.ServerProtocolFactor y.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

supera
Jul 09, 2012, 1:29 PM

Daniil
Jul 09, 2012, 3:15 PM
The WebService is broken due to the "multipart/form-data" form attribute.

The possible solution can be:

1. Remove the pID parameter on the WebService.

Public Sub DownloadFileAjax()

2. Read that parameter directly from the Request:

HttpContext.Current.Request["fileName"]; //C#

supera
Jul 09, 2012, 5:38 PM

Daniil
Jul 09, 2012, 5:49 PM
If you would like to turn back to WebService, you will know what you should do:)