I am consuming a asmx service and trying to do async/await while trying to call it
Currently My controller is like below
Public ActionResult Index()
{
var data = _repository.GetDataFromAsmxService(somedata);
}
//RepositoryClass Method
public List<ObjectToReturn> GetDataFromAsmxService(somedata)
{
var res = _asmxService.GetReportData(somedata);
var result = process(res);
return result;
}
Upon further looking at refrence.cs file generated found there were void async and onCompleted methods for equivalent calls.
So i changed it to
private void GetReportDataCallBack(object sender, GetReportDataCompletedEventArgs e)
{
var res = e.Result;
var result = process(res);
}
public List<ObjectToReturn> GetDataFromAsmxService(somedata)
{
_asmxService.GetReportDataCompleted +=GetReportDataCallBack;
_asmxService.GetReportDataAsync(somedata);
}
but now the callback happens to the Event delegate so my controller expecting a return data won’t get it. what is a better way to call async/await from controller and get the data from asmx webservice
Code From Refenrece.cs //Generated code
[System.Web.Services.Protocols.SoapHeaderAttribute("ApiAuthenticationValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://webservice.com/GetReportData", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute(Namespace="http://webservice.com/")]
public GetReportDataResponse GetReportData([System.Xml.Serialization.XmlElementAttribute(Namespace="http://webservice.com/")] GetReportDataRequest GetReportDataRequest) {
object[] results = this.Invoke("GetReportData", new object[] {
GetReportDataRequest});
return ((GetReportDataResponse)(results[0]));
}
/// <remarks/>
public void GetReportDataAsync(GetReportDataRequest GetReportDataRequest) {
this.GetReportDataAsync(GetReportDataRequest, null);
}
/// <remarks/>
public void GetReportDataAsync(GetReportDataRequest GetReportDataRequest, object userState) {
if ((this.GetReportDataOperationCompleted == null)) {
this.GetReportDataOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetReportDataOperationCompleted);
}
this.InvokeAsync("GetReportData", new object[] {
GetReportDataRequest}, this.GetReportDataOperationCompleted, userState);
}
private void OnGetReportDataOperationCompleted(object arg) {
if ((this.GetReportDataCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetReportDataCompleted(this, new GetReportDataCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
GetReportData
? – Scott Chamberlain