Link to home
Start Free TrialLog in
Avatar of egrolpe
egrolpe

asked on

use of a web service

Hello.
This is the first time I use web service.
I created a simple web service (the project is java web application) on my computer.
now, another application need to use it. this application is on another computer (B) on the network.
I want to place the web service I created in a computer (A) on the network as well.  (both computer ar in the same network)
What files do I need to copy to computer A ?
How the app from computer B communicate with the web service on computer A? What info do I need to supply?
Is there any security issues I need to worry about ? How can I set a username+password to the web service ?

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can show you how this is done with a very simple teaching example, written in PHP.  This uses RESTful design, which in my opinion is much easier to get right than SOAP.  The world-wide-web is a RESTful design.  More on REST here.
http://en.wikipedia.org/wiki/Representational_state_transfer
http://www.ibm.com/developerworks/webservices/library/ws-restful/

The script below is located at on my server at this URL.  Try a couple of these to see how it works.
http://www.laprbass.com/RAY_REST_get_last_name.php?key=ABC&name=Ray
http://www.laprbass.com/RAY_REST_get_last_name.php?key=ABC&name=egrolpe
http://www.laprbass.com/RAY_REST_get_last_name.php?key=FOO&name=Ray

So to sum up, in the REST design, each request is atomic and complete, providing the parameters as GET arguments in the URL.  And each response is complete and usually instantaneous, written in clear text to the browser output stream.  It is a stateless protocol.  Neither party needs to know how the other makes the request or response.  The requesting client needs only to know what format the server will use for the response.  That is usually documented in the API documentation.  An example of the API documentation for one of my web services is here.
http://www.carpool2camp.org/v2api/apidocs.php

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



// DEMONSTRATE HOW A RESTFUL WEB SERVICE WORKS
// INPUT FIRST NAME, OUTPUT FAMILY 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'
)
;


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



// TEST THE 'API KEY' - THIS COULD BE A DATA BASE VALIDATION LOOKUP - AS SIMPLE OR COMPLEX AS NEEDED
$key = (!empty($_GET["key"])) ? $_GET["key"] : FALSE;
if ($key !== 'ABC')
{
    echo $alpha . 'BOGUS API KEY' . $omega;
    die();
}



// LOOK UP THE FAMILY NAME
$name = (!empty($_GET["name"])) ? $_GET["name"] : FALSE;

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

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

Open in new window