how to making async call to proxy webreference created from asmx webservice
-
I have created proxy services by add web reference in my Xamarin.Droid project to access asmx webservice. Eg: I have a webservice for feature master when I make a direct request with URL "http://XX.XX.XXX.XXX/tabsaleswithdatasync.asmx/FeatureMaster" I am getting following info
[{"msg":"","FeatureSlno":"2","Feature":"Fuel Used","DefaultValue":"","FeatureType":"B","Groups":"OverView","GroupOrder":"0","SubGroupOrder":"0","CategorySlno":"2","UtilisationSlno":"1","IconImagePath":"","LowerIsBetter":"0"},{"msg":"","FeatureSlno":"3","Feature":"Seating Capacity","DefaultValue":"","FeatureType":"B","Groups":"OverView","GroupOrder":"0","SubGroupOrder":"0","CategorySlno":"3","UtilisationSlno":"0","IconImagePath":"","LowerIsBetter":"0"}]
I have written my method to get data EngageWebReference.TabSalesWithDataSync objProxy = new EngageWebReference.TabSalesWithDataSync(); objProxy.FeatureMasterCompleted += ObjProxy_FeatureMasterCompleted; objProxy.FeatureMasterAsync(); private void ObjProxy_CityMasterCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { // here I am getting XMLException as data at the root level is invalid. line 1 position 1. throw new NotImplementedException(); } Can anyone suggest how to make async call get the desired result into a variable eg: List res = new List res = GetFeatureMasterList();
-
I have created proxy services by add web reference in my Xamarin.Droid project to access asmx webservice. Eg: I have a webservice for feature master when I make a direct request with URL "http://XX.XX.XXX.XXX/tabsaleswithdatasync.asmx/FeatureMaster" I am getting following info
[{"msg":"","FeatureSlno":"2","Feature":"Fuel Used","DefaultValue":"","FeatureType":"B","Groups":"OverView","GroupOrder":"0","SubGroupOrder":"0","CategorySlno":"2","UtilisationSlno":"1","IconImagePath":"","LowerIsBetter":"0"},{"msg":"","FeatureSlno":"3","Feature":"Seating Capacity","DefaultValue":"","FeatureType":"B","Groups":"OverView","GroupOrder":"0","SubGroupOrder":"0","CategorySlno":"3","UtilisationSlno":"0","IconImagePath":"","LowerIsBetter":"0"}]
I have written my method to get data EngageWebReference.TabSalesWithDataSync objProxy = new EngageWebReference.TabSalesWithDataSync(); objProxy.FeatureMasterCompleted += ObjProxy_FeatureMasterCompleted; objProxy.FeatureMasterAsync(); private void ObjProxy_CityMasterCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { // here I am getting XMLException as data at the root level is invalid. line 1 position 1. throw new NotImplementedException(); } Can anyone suggest how to make async call get the desired result into a variable eg: List res = new List res = GetFeatureMasterList();
Yeah...just a guess but your error is most likely related to the data being in JSON rather than XML. Try parsing with Newtonsoft, or pass an "Accept: application/xml" header.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
-
Yeah...just a guess but your error is most likely related to the data being in JSON rather than XML. Try parsing with Newtonsoft, or pass an "Accept: application/xml" header.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
-
Deserialize the result from the webservice to a .Net class:
Newtonsoft.Json.JsonConvert.DeserializeObject
It's a Nuget package you add to your project to get the dll references.
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
What Gerry said. Alternatively the agent you're using to make the request (such as HttpClient) can be configured to send custom accept headers, and if the web service supports it you can request the data in XML form instead, which was the second part of my suggestion.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
-
What Gerry said. Alternatively the agent you're using to make the request (such as HttpClient) can be configured to send custom accept headers, and if the web service supports it you can request the data in XML form instead, which was the second part of my suggestion.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
-
As I am using ASMX I think I cant configure to return XML. I have JSON data returning. Is there any possibilities to consume JSON from webservice with an Async call. I am new to C# and Xamarin.
Yes, as I said and Gerry clarified. If you need help with the nuts and bolts we can provide that, but with the information you've given we don't even know how you're consuming the service, let alone any implementation details.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
-
Yes, as I said and Gerry clarified. If you need help with the nuts and bolts we can provide that, but with the information you've given we don't even know how you're consuming the service, let alone any implementation details.
"There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli
Thank you, I was trying to consume ASMX web service as instructed in Xamarin ASMX Consuming an ASP.NET Web Service (ASMX) - Xamarin[^] I could make out the expected output was not as per the standards are given SOAP 1.1. So I have to modify the ASMX service Thank you again