Hi
I got a couple question about web services
I know in web services you can't return stuff like dataTableRows and dataTableColumns and that you can only return dataSets back and even that is not recommended.
I am wondering however can you still use them in as long as you don't return those thing in the end?
Like I tried to make a dataset file(dataset.xsd) and I then made a class to hold my logic. I just did one simple sql statement to just count the number of rows.
*note the variable names are not relevant. I just basically copied old code and change it around a bit.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService2.DataSet1TableAdapters;
namespace WebService2
{
public class Class1
{
private DataTable1TableAdapter chartsAdapter = null;
protected DataTable1TableAdapter ChartsAdapter
{
get
{
if (chartsAdapter == null)
{
chartsAdapter = new DataTable1TableAdapter();
}
return chartsAdapter;
}
}
public int grabCount()
{
// this is what my DataSet.xsd file holds for the sql
// SELECT COUNT(StudentID) AS Expr1
// FROM Students
return Convert.ToInt32(ChartsAdapter.GetDataCount());
}
}
}
Then in my Web Service file(Service.asmx.cs)
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService2
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int test()
{
Class1 tes = new Class1();
return tes.grabCount();
}
}
}
So as you can see I am just making a new object of Class and then trying to get the count back that returns a int.
However when I try to test my web service I get this error.
System.InvalidCastException: Unable to cast object of type 'DataTable1DataTable' to type 'System.IConvertible'.
at System.Convert.ToInt32(Object value)
at WebService2.Class1.grabCount() in I:\WebService2\Class1.cs:line 30
at WebService2.Service1.test() in I:\WebService2\Service1.asmx.cs:line 30
So I am not sure what is going on.
So I am using an access database, Visual Studios 2008, Web Service Application.