Science Library - free educational site

Data Management Techniques

Simple Object Access Protocol (SOAP) is a protocol for cross-server and cross-application communication. It is based on XML, is language and platform independent, and is recommended by W3C.

SOAP is needed when normal internet access is blocked by security and compatibility preventions, and firewalls. With SOAP, different applications on different operating systems can exchange information, access databases on remote servers, without heed of language level or type.

SOAP components

There are four elements to the SOAP architecture:

The Envelope

An XML document needs to be declared as a SOAP message, so an envelope is placed around it:

<?xml version="1.0"?>

<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>

<m:Trans xmlns:m="http://www.w3schools.com/transaction/" soap:mustUnderstand="1">value

</m:Trans>

</soap:Header>

<soap:Body>

<m:GetClients xmlns:m="http://www.sciencelibrary.info/clients">

<m:Item>First_name</m:Item>

</m:GetClients>

</soap:Body>

</soap:Envelope>

The Header

Header information is optional for the SOAP call. The parts of the header include whether the call must comply to the optional header (soap:mustUnderstand="1"), the Actor, which points the header to a specific endpoint (soap:actor="URI"), and encoding (soap:encodingStyle="URI").

The Body

The call and response information is stored in the body element:

<soap:Body>

<m:GetClients xmlns:m="http://www.sciencelibrary.info/clients">

<m:Item>First_name</m:Item>

</m:GetClients>

</soap:Body>

The Fault element

Errors and other information regarding the status of the SOAP call is returned in the Fault element.

Random String Generation

Random string generation involves a simple application which is extremely useful for a wide range of applications.

We define the function str_rand, which is based on the PHP mt_rand, to generate the string:


function str_rand($len = 32, $chars='0123456789abcdefghijk
lmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
    $str = '';
    for ($i = 0; $i < $len; $i++) {
        $str .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    return $str;
}

With this function we can create an impressive number of different strings. With the values of $len and $chars as the basis, we have a string which is 32 characters long, selected from 62 characters, or 3262 permutations. Let's use Python to make the calculation:

>>> "%.2g" % 32**62
'2.1e+93'

Not enough? Given that the combinations increase exponentially, by simply doubling the length $len of the string, we obtain 9.6 x 10111 possible results, or more than 4 billion billion times the previous number!

However, a high probability is not enough to guarantee that all of the generated strings are unique. As programmers we have to remain on the defensive, and be 100% sure that they can be no conflicts. It is sufficient to add a simple loop to ensure this condition is met:

// List of keys already generated and not to be repeated 
//- for example from a databank 
$keys = array(...);

$k = str_rand();

while (in_array($k, $keys)) {
    $k = str_rand();
}

Given the high number of possible keys, the condition in_array($k, $keys) will be nearly always false, but if the number of keys already existing is very high and/or the number of possible combinations must be restricted (for example, shortening the key or including only the lower case letters in the initial $chars set), it would be too involved to check every time all the values of $keys. At this point, we could devise a more refined method for generating keys, but for most requirements this method works perfectly.

Content © Renewable.Media. All rights reserved. Created : November 28, 2014 Last updated :March 7, 2016

Latest Item on Science Library:

The most recent article is:

Trigonometry

View this item in the topic:

Vectors and Trigonometry

and many more articles in the subject:

Subject of the Week

Resources

Science resources on ScienceLibrary.info. Games, puzzles, enigmas, internet resources, science fiction and fact, the weird and the wonderful things about the natural world. Have fun while learning Science with ScienceLibrary.info.

Science

Great Scientists

Tycho Brahe

1546 - 1601

Tycho Brahe was a Danish astronomer, whose meticulous observations and ideas about the nature of planets, stars and comets, although erroneously accommodating rather than directly challenging the long-standing Aristotelian and Ptolemaic versions of the heavens, they were nevertheless an important contribution to the coming scientific revolution, and specifically enabled his assistant, Johannes Keppler, to derive his breakthrough laws of planetary motion.

Tycho Brahe
IT Forum by Sean Bone

Quote of the day...

The factory of the future will have only two employees: a man and a dog. The man will feed the dog. The dog will prevent the man from touching the machines.

Renewable.Media Internet Promotions

English language school