Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Websrvice sql for server stored procedure

Websrvice sql for server stored procedure

Scheduled Pinned Locked Moved Web Development
databasesharepointsql-serversysadminjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    billythekidney
    wrote on last edited by
    #1

    Hi, I have a Sql Server 2008 database on a website and need to develop a web service using JSON to call from remote devices for running stored procedures. Does anyone have any sample code of a web service running a sp with input parameters, producing a JSON result set that I can have a look at? Thanks

    Anthony

    J 1 Reply Last reply
    0
    • B billythekidney

      Hi, I have a Sql Server 2008 database on a website and need to develop a web service using JSON to call from remote devices for running stored procedures. Does anyone have any sample code of a web service running a sp with input parameters, producing a JSON result set that I can have a look at? Thanks

      Anthony

      J Offline
      J Offline
      Jasmine2501
      wrote on last edited by
      #2

      Several things have to come together to give JSON back to the browser... your service has to be decorated like this...

      [ScriptService]
      public class wMDTServices {
      [WebMethod]
      //public String Read(int skip, int take, IEnumerable<Sort> sort, Filter filter)
      public List<DataRow> Read() {
      try {
      //changed this to use something I could find that might work, it had a compilation error - DA
      DataSet result = OracleSQLHelper.RetrieveFromSQL("Some Query");

              var myList = new List<DataRow>();
      
              foreach (DataRow r in result.Tables\[0\].Rows) {
                  myList.Add(r);
              }
      
              return myList;
          } catch {
              return null;// Newtonsoft.Json.JsonConvert.SerializeObject(exception);
          } finally { }
      }
      

      }

      Then, you have to call it with the right content type, like this... (part of a JQuery Ajax call)

      transport: {
      read: {
      url: myWebServiceUrl + "/Read",
      dataType: "json",
      type: "post",
      contentType: "application/json; charset=utf-8"
      }
      }

      The important things there are the contentType, the "post" request type, and the datatype "json" which are all needed to tell the web service that you want JSON back. If all these things are received by the server correctly, it will send back JSON strings.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups