Solved

Web Services Newbie

Posted on 2011-02-22
3
383 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 109

Accepted Solution

by:
Ray Paseur earned 500 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 109

Expert Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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