I have a SOAP web service with which I retrieve various information. Most functions work correctly, but I need some functions to return a List .
WebMethod defined as:
List<MyType> myTypes = new List<MyTypes>(); [WebMethod] public List<MyType> GetAllMyTypes() { string sql = "SELECT * FROM MyType"; DataTable dt = new DataTable(); dt = Globals.GLS_DataQuery(sql); List<MyType> myType = new List<MyType>(); foreach (DataRow row in dt.Rows) { MyType myType = new MyType() { ID = (int)row["Id"] }; myTypes.Add(myType); } return myTypes; }
The web service is referenced in the main project and called:
client.GetAllMyTypesCompleted += client_GetAllMyTypesCompleted; client.GetAllMyTypesAsync();
client_GetAllMyTypesCompleted defined as:
private void client_GetAllMyTypesCompleted(object sender, GetAllMyTypesCompletedEventArgs e) { var collection = e.Result; }
This is where a TargetInvocationException is thrown, especially with respect to Result . If you start the web service yourself, the correct data will be returned. For reference, GLS_DataQuery is defined as:
public static DataTable GLS_DataQuery(string sql) { DataTable dt = new DataTable SqlCommand command = new SqlCommand(sql, connection); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(dt); return dt; }
So why am I seeing this error? Or how should I return a list of objects in this instance?
Perhaps the relevance of the web service is hosted on Azure.
EDIT: Binding a debugger to an instance of a web service running in Azure sees that it is returning the correct data. The error is caused in the Xamarin application for the phone, which calls the web service. The error message is just a zero reference error, and the stack trace:
in MyApp.MyService.Service1SoapClient.EndGetAllMyTypes (IAsyncResult result) in MyApp.MyService.Service1SoapClient.OnEndGetAllMyTypes (IAsyncResult result) in System.ServiceModel.Onclientes``
c # soap web-services azure xamarin
anothershrubery
source share