Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Web Services Newbie

Posted on 2011-02-22
3
Medium Priority
?
387 Views
Last Modified: 2012-05-11
I have a VS 2008 app with a SQL Server 2008 database that I want to communicate with a customer's legacy system.  To simplify my question, let's say it's an inventory application.
My system handles receipts, issues and inventories.  I update my inventory and transaction tables according to the type of transaction.  For example, if it's a receipt, I increment my inventory level (or create a new record if the item is not already in inventory) and I add a record to the transaction table.
My question is:  Would it be better to have specific web services for all transaction types (receipt, issue and inventory) where I only pass the data fields needed or would the web services simply handle inserts, deletions and updates and I would pass my entire dataset and let the web service determine how to handle each transaction.
0
Comment
Question by:PSCTECH
  • 2
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 34960039
Either way would work.  If it were up to me I would create a RESTful web service and send it commands in the URL GET request (for data retrieval only) or via POST for those commands that modify the data model.  A REST service can be as simple or as complex as you want to make it.  Good examples include the Google V3 API that draws maps, of at the simple end of things, this little script that takes a first name as input and returns the last name as output.  To see it in action, visit
http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Ray

You can try experimenting with different arguments to see what it does.  If you want to learn more about REST, look up the Wikipedia article.
http://en.wikipedia.org/wiki/Representational_State_Transfer

If that seems like a daunting amount of information, here are the important points.  REST is the protocol that underlies client-server networks.  Clients initiate requests and servers respond.  Each request is atomic.  Each response is complete.  The client has no need to know what the server is doing or how the server is doing it.  This elegant and simple separation of responsibilities makes it amazingly easy to develop client-server web services.

The contrast is the awkward and complicated thing called SOAP, and I advise you to stay away from that.  The web is littered with failed SOAP projects.  I have never met anyone who could not get a REST service running correctly.

Best of luck with it, ~Ray
<?php // RAY_REST_get_last_name.php
error_reporting(E_ALL);



// DEMONSTRATE HOW A RESTFUL WEB SERVICE WORKS
// INPUT FIRST NAME, OUTPUT LAST NAME
// CALLING EXAMPLE:
// file_get_contents('http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Ray');



// OUR DATA MODEL CONTAINS ALL THE ANSWERS - THIS COULD BE A DATA BASE - AS SIMPLE OR COMPLEX AS NEEDED
$dataModel
= array
( 'Brian'   => 'Portlock'
, 'Ray'     => 'Paseur'
, 'Richard' => 'Quadling'
, 'Dave'    => 'Baldwin'
)
;


// SHOULD RESPONSE BE PLAIN TEXT OR XML FORMAT
$alpha = '';
$omega = '';
if ( (isset($_GET["resp"])) && ($_GET["resp"] == 'XML') )
{
    $alpha = '<response>';
    $omega = '</response>';
}



// TEST THE API KEY
$key = FALSE;
if (isset($_GET["key"])) $key = $_GET["key"];
if ($key !== 'ABC') die($alpha . 'BOGUS API KEY' . $omega);



// LOOK UP THE LAST NAME
$name="?";
if (isset($_GET["name"])) $name = $_GET["name"];

// IF THE URL NAME IS FOUND IN THE DATA MODEL
if (array_key_exists($name, $dataModel))
{
    // RETURNS THE LAST NAME FROM THE DATA MODEL
    die($alpha . "$dataModel[$name]" . $omega);
}

// RETURNS THE UNKNOWN NAME INDICATOR
else die($alpha . 'UNKNOWN' . $omega);

Open in new window

0
 

Author Closing Comment

by:PSCTECH
ID: 34961311
Great answer, quick response, very helpful.  Thank you
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34962331
Thanks for the points!  Best of luck with your project, ~Ray
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question