title: WCF web service return special JSON response
body: <p>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.</p>
  
  <p>If the parameters are valid the response is <code>{"success":1}</code>, if not the response is <code>{"success":0,"error_message":"The parameters are invalid."}</code>. The web service that does this was done in PHP. All works fine. </p>
  
  <p>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. </p>
  
  <p>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 <code>{"success":1}</code>, and if no data in the result, then respond with <code>{"success":0,"error_message":"The parameters are invalid."}</code>. I am not including the <strong>IService1.cs</strong>, the <strong>web.config</strong> or the <strong>CustomerOrdersOrders.cs</strong> code since I'm not sure they are required to solve my problem. If they are, let me know and I will post them.</p>
  
  <p>Any help is appreciated.</p>
  
  <pre><code>public List&lt;CustomerOrdersOrders&gt; GetCustomerOrdersOrders(string customerID)
          {
              NorthwindDataContext dc = new NorthwindDataContext();
              List&lt;CustomerOrdersOrders&gt; results = new List&lt;CustomerOrdersOrders&gt;();
              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;
  
          }
  </code></pre>