I have an async ASMX web method which works as expected when passing a simple string (I followed the excellent information provided by Stephen Cleary on this question Calling Task-based methods from ASMX
If I post a json object via an XmlHttpRequest to a sync method, this works OK (the object’s underlying type is Dictionary<string,object>
but if I try to pass the same js object to the async version, I get the Unknown web method error, even though the WSDL indicates that the method MyDownload exists.
What am I doing wrong/missing?
Javascript:
let jobUrl = '@Helpers.GetUrl(Request, "SiteService.asmx/MyDownload", false)'; //Fails
//let jobUrl = '@Helpers.GetUrl(Request, "SiteService.asmx/MyTest", false)'; // Succeeds
let tmp = {};
tmp.myDownloadViewModel = @Html.Raw(Json.Encode(Model));
ajaxQuery(jobUrl, 'POST', 'json', tmp, function (result) {
...
});
SiteService.asmx.cs:
using ...
namespace MyCompany.Namespace
{
/// <summary>
/// Summary description for SiteService1
/// </summary>
[WebService(Namespace = "http://mycompany.co.uk/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class SiteService : System.Web.Services.WebService
{
[WebMethod]
public string MyTest(object myDownloadViewModel)
{
var x = 1;
return "ok";
}
// Async webmethod info from Stephen Cleary https://stackoverflow.com/questions/24078621/calling-task-based-methods-from-asmx
private async Task<string> FooAsync(string patientId)
{
....
}
[WebMethod]
public IAsyncResult BeginMyDownload(object myDownloadViewModel, AsyncCallback cb, object state)
{
...
}
[WebMethod]
public string EndMyDownload(IAsyncResult res)
{
return ((Task<string>)res).GetAwaiter().GetResult();
}
}
}