Solved

Web Services Newbie

Posted on 2011-02-22
3
377 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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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
Comment Utility
Great answer, quick response, very helpful.  Thank you
0
 
LVL 108

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now