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

Jul 06, 2012, 6:55 PM

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:

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
.AddHeader("Content-Disposition", "attachment; filename=" & Doc.FileName)
.AddHeader("Content-Length", tmpFile.Length.ToString())
.ContentType = "application/octet-stream"
.OutputStream.Write(tmpFile, 0, tmpFile.Length)
End With
End If
End Sub

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

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

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

Thanks for any help!

Jul 08, 2012, 8:47 PM

I think you should correct the directRequest config.

1. Remove

json: true

2. Add

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

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

I'm doing some wrong...

I changed my source code as you sugested...

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

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)

Jul 09, 2012, 1:29 PM

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#

Jul 09, 2012, 5:38 PM

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