-1

I have a task at work ,using web services , to make communication between a web site based on Classic Asp & an application based on android platform , to create function with a parameter Date which provide data from the bd,i dont have any idea how to proceede , can u plz give me an example or tutos to follow ?

Hasnae Idem
  • 39
  • 1
  • 10

1 Answers1

2

Your easiest option is to produce json (which can easily be consumed by the android side) like this:

ASP "service"

<!-- 
this is one example of a library of json helpers that you can use. 
You can get it from this page
http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/
http://www.webdevbros.net/wp-content/uploads/2008/07/json151.zip
save the downloaded json.asp file in the same folder as your .asp 
-->

<!--#include file="json.asp" -->

<%
    REM 1. Create and populate ADO Recordset from database
    REM   Note: I am providing just an example and you might 
    REM   ant to look into using a more appropriate command type 
    REM   or cursor type when populating your recordset        

    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "put your connection string here"
    Set cmd = Server.CreateObject("ADODB.Command")
    cmd.CommandType = adCmdText 'note must have this constant defined in scope'
    Set cmdTemp.ActiveConnection = conn

    cmd.CommandText = "put your SQL here; be careful to protect against SQL injections" 

    Set rs = Server.CreateObject("ADODB.Recordset")

    rs.Open cmd, ,adOpenForwardOnly,adLockReadOnly 'note make sure these constants are defined in scope'

    REM 2. Prepare json
    Dim jsonObject

    Set jsonObject = New JSON   'JSON class is in the include file json.asp'
    jsonResult = jsonObject.toJSON(Empty, rs, False) 'You may have to play with the parameters here, if the way json is formatted does not suit you'
                                                   'check the documentation of json.asp library'

    REM 3. stream json to client
    Response.ContentType = "application/json" 
    Response.Write jsonResult
%>

You could find more libraries that help format values or structures into JSON: just search for "classic ASP" + JSON on SO or google. Here's one library that takes vbscript/ASP structures and outputs them in JSON. Look at the SQL example.

Check this SO thread for more "classic" ASP and JSON

Community
  • 1
  • 1
G. Stoynev
  • 7,389
  • 6
  • 38
  • 49
  • thank you , i've made a research i didnt find any tutoriel on google :( need some help :s – Hasnae Idem Mar 29 '13 at 17:00
  • To create your "web service", create an ASP page on the server that does something similar to what I show above. To "produce" the JSON output, "include" and use one of the many libraries found online. I edited my answer to reference one - check out its SQL example. – G. Stoynev Mar 31 '13 at 21:22
  • Im really stuck on this , can u plz give me an example of the prototype on how to prépare json ..& stream json to client ... i need a concret example A to Z :( ...from the service ASp to the JSON output plzzzz – Hasnae Idem Apr 02 '13 at 15:09
  • How can a consume this web service plz ?? im php programmer , i have a temporary task this week with asp & webservices..:s – Hasnae Idem Apr 03 '13 at 14:21
  • The page will stream text string, formatted as JSON - just hit the URL in a browser and you'll see page's output. You mentioned that the client will be an Android app - this is outside of the scope of this question. And please try to do some searches and read-up and only post questions that seek answers to specific problems. – G. Stoynev Apr 03 '13 at 14:52
  • its okey i've finished my task , & its only with ur help im thkful to u , i didnt have time to learn more about web services that's why i've posted this topic , thank u very much. – Hasnae Idem Apr 03 '13 at 15:51