Solved

Web Services Newbie

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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