I wrote an iOS app that uses a Post HTTP method via a URL and two parameters that checks the validity of the two parameters against records in a table in a mySQL database and returns a JSON response.
If the parameters are valid the response is {"success":1}
, if not the response is {"success":0,"error_message":"The parameters are invalid."}
. The web service that does this was done in PHP. All works fine.
However, now I want to do the same thing against an MSSQL database using a WCF web service. I did some research and I actually have it working whereby I am using a stored procedure in the web service and the response is returned in JSON format.
I am new to WCF web services and C#.NET and I am trying to figure out how to have the response not return the results from the stored procedure but just a JSON response indicating if there are results and another response if there are no results. The code for my test WCF web service (Service1.svc.cs) is below and this brings back all the data in JSON, but all I want is if there is data in the result then respond with {"success":1}
, and if no data in the result, then respond with {"success":0,"error_message":"The parameters are invalid."}
. I am not including the IService1.cs, the web.config or the CustomerOrdersOrders.cs code since I'm not sure they are required to solve my problem. If they are, let me know and I will post them.
Any help is appreciated.
public List<CustomerOrdersOrders> GetCustomerOrdersOrders(string customerID)
{
NorthwindDataContext dc = new NorthwindDataContext();
List<CustomerOrdersOrders> results = new List<CustomerOrdersOrders>();
System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.GetCultureInfo("en-US");
foreach (CustOrdersOrdersResult oneOrder in dc.CustOrdersOrders(customerID))
{
results.Add(new CustomerOrdersOrders()
{
OrderID = oneOrder.OrderID,
OrderDate = (oneOrder.OrderDate == null) ? "" : oneOrder.OrderDate.Value.ToString("d", ci),
RequiredDate = (oneOrder.RequiredDate == null) ? "" : oneOrder.RequiredDate.Value.ToString("d", ci),
ShippedDate = (oneOrder.ShippedDate == null) ? "" : oneOrder.ShippedDate.Value.ToString("d", ci)
});
}
return results;
}