PDA

View Full Version : [CLOSED] Ext.net.DirectMethod.request webservice call and isUpload



CarpFisher
Sep 27, 2012, 6:44 PM
Hi

Using the examples http://examples2.ext.net/#/Events/DirectMethods/WebService/

I am calling a WebService Endpoint from a DirectMethod, only difference is my service returns the actual file for download from the asmx file. Here is the function and I've tested it without problem by called it directly.




[WebMethod]
public void DownloadScript(string script)
{

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "UTF-16";
HttpContext.Current.Response.ContentType = "application/x-pmt; charset=\"UTF-16\"";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode;
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename="+ ts.Name+ ".pmt");
HttpContext.Current.Response.BinaryWrite(System.Te xt.Encoding.Unicode.GetPreamble());
HttpContext.Current.Response.Write(script);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();


}



I know I need isUpload = true somewhere, otherwise I'm going to get BadResponse. However doesn't matter if I put isUpload or not in the following code, it still return BADRESPONSE: Cannot read property 'documentElement' of null


MyControl.Listeners.Click.Handler = @"
Ext.net.DirectMethod.request({
url : '/TestScriptWS.asmx/DownloadScript',
isUpload : true,
cleanRequest : true,
json : true,
params : {
script : '1234'
}
});
";


It seems that DirectMethod.request doesn't read that isUpload parameter.... where should I put that? I've spend long time trying to figure that out but no joy. Thank you very much

Daniil
Sep 27, 2012, 6:53 PM
Hi @CarpFisher,

AJAX downloading requires a <form>.

Please define a <form>.

<form id="form1" class="x-hidden"></form>
and refer it in the DirectMethod config

formId: "form1"

CarpFisher
Sep 27, 2012, 7:26 PM
not working :(

I've got this error after formId is defined


System.InvalidOperationException: Request format is invalid: multipart/form-data; boundary=----WebKitFormBoundaryiCoYwSAmMGdO8yW4.
at System.Web.Services.Protocols.HttpServerProtocol.R eadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Co reProcessRequest()


Am I missing anything?

CarpFisher
Sep 27, 2012, 7:30 PM
This is the info I've got from Chrome's developer tool



Request URL:http://localhost:3269/WebServiceHandlers/TestScriptWS.asmx/DownloadScript
Request Method:POST
Status Code:500 Internal Server Error


Request Headers:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:381
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryXPeMdCUDo9oWvW0x
Cookie:ASP.NET_SessionId=kwqsu2lgddynenalgx2iqcsn
Host:localhost:3269
Origin:http://localhost:3269
Referer:http://localhost:3269/
User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
Request Payload
------WebKitFormBoundaryXPeMdCUDo9oWvW0x
Content-Disposition: form-data; name="__EVENTTARGET"

ResourceManager1
------WebKitFormBoundaryXPeMdCUDo9oWvW0x
Content-Disposition: form-data; name="__EVENTARGUMENT"

-|public|Click
------WebKitFormBoundaryXPeMdCUDo9oWvW0x
Content-Disposition: form-data; name="{%22ScriptID%22:3}"


------WebKitFormBoundaryXPeMdCUDo9oWvW0x--
Response Headers:

Cache-Control:private
Content-Length:281
Content-Type:text/plain; charset=utf-8
Date:Thu, 27 Sep 2012 18:27:31 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcdGZzXFNvdXJjZSAtIFVBVFxQTVBUZXN0XFBNUFRlc3 RNYXN0ZXJTZXJ2ZXJXZWJcV2ViU2VydmljZUhhbmRsZXJzXFRl c3RTY3JpcHRXUy5hc214XERvd25sb2FkU2NyaXB0?=

Vladimir
Sep 27, 2012, 8:21 PM
It is not Ext.Net problem

You can read about the issue
http://www.developersalley.com/blog/post/2011/06/22/SystemInvalidOperationException-Request-format-is-invalid-multipartform-data-boundary-Error-When-Calling-Net-Web-Service-from-PHP.aspx
http://forums.asp.net/t/1551950.aspx/1
http://stackoverflow.com/questions/2067742/system-invalidoperationexception-request-format-is-invalid-multipart-form-dat

Solution: do not use parameters in WebMethod, read passed parameters manually from Request object

CarpFisher
Sep 28, 2012, 9:24 AM
Thank you it works. Just a little thing to note that I have to use
json: false otherwise the variable name in the form will be a json object and you can't really retrieve that from the Request object in the usual way.

Daniil
Sep 28, 2012, 10:11 AM
By the way, false is by default. You can just omit this.