Date post: | 02-Jan-2016 |
Category: |
Documents |
Upload: | norman-chandler |
View: | 216 times |
Download: | 1 times |
SOAP and WSDL
DIG 4104c Web Design WorkshopMichael Moshell
Spring 2013
annalaurabrown.com cubaninsider.blogspot.com
cubaninsider.blogspot.com
We're not really washing weasels ...We're CONNECTING programs on
different COMPUTERS.
galloinspires.com
cubaninsider.blogspot.com
We're not really washing weasels ...We're CONNECTING programs on
different COMPUTERS.
The Lead Retrieval Story
At a conference, Exhibitorswant Leads – names and
contact information for follow-up marketing.
galloinspires.com
Attendees have badges (with barcodes)or cards (with chips or mag stripes)
Which are scannedat the booths ...
Data from the scannersgoes onto RAM sticks (or through the Internet)to sales people who follow up, next dayor next week,
to close the sale, build a relationship
bartizan.com
bartizan.com
expectnation.com
Our problem: Making the cards
Clientregisters
viabrowser
Clientregisters
viabrowser
Onlinesystem
capturesdata
Sendsdata to
mag cardcomputer
Onlinesystem
capturesdata
Sendsdata to
mag cardcomputer
mag cardcomputer
sendsdata to
mag cardprinter
mag cardcomputer
sendsdata to
mag cardprinter
zebra.com
Our solution (pre-SOAP):Polling a PHP "server"
Clientregisters
viabrowser
Clientregisters
viabrowser
regmasterwrites
text files
regmasterwrites
text files
mag cardcomputer
polls (repeatedly asks)"do you have
$asknumber yet?
mag cardcomputer
polls (repeatedly asks)"do you have
$asknumber yet?
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
PHP server:$asknumber ==
nextnumber.txt?
if so,send
trans($asknumber)
if not,send "NO"
PHP server:$asknumber ==
nextnumber.txt?
if so,send
trans($asknumber)
if not,send "NO"
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
$asknumber?
NOortext file
Our solution (pre-SOAP):Polling a PHP "server"
Clientregisters
viabrowser
Clientregisters
viabrowser
regmasterwrites
text files
regmasterwrites
text files
runget.phploops and
asks, every 2 seconds"Do you have 21047?
runget.phploops and
asks, every 2 seconds"Do you have 21047?
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
runsend.phprunsend.php
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
21047?
NOortext file
Our solution (pre-SOAP):Polling a PHP "server"
Review the code: runsend, runget.
One fixup: The transfer dataShould be urlencoded!
This is regular text, with punctuation, said O'Reilly
URLencoded:This+is+regular+text%2C+with+punctuation%2C+said+O%27Reilly
Our solution (pre-SOAP):Polling a PHP "server"
Clientregisters
viabrowser
Clientregisters
viabrowser
regmasterwrites
text files
regmasterwrites
text files
runget.phploops and
asks, every 2 seconds"Do you have 21047?
runget.phploops and
asks, every 2 seconds"Do you have 21047?
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
runsend.phprunsend.php
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
21047?
NOortext fileAdvantages:
HTTPS all the way; firewall OK
Our solution (pre-SOAP):Polling a PHP "server"
Clientregisters
viabrowser
Clientregisters
viabrowser
regmasterwrites
text files
regmasterwrites
text files
runget.phploops and
asks, every 2 seconds"Do you have 21047?
runget.phploops and
asks, every 2 seconds"Do you have 21047?
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
runsend.phprunsend.php
nextnumber.txttrans21044.txttrans21045.txttrans21046.txt...
21047?
NOortext fileDisadvantages:
Polling uses CPU and Internetresources; fragile synchronization
21047?
NOortext file
Fragile synchronization?
Runget must know which number to ask for.If runsend somehow misses a number, system hangs.
Better way: Instead of asking for 21047, ask"what do you have that's new?
SO let's design a solution using SOAP.
SOAP comes in two flavors(scented and unscented? Nope ...)
WITH and WITHOUT weasels!
(Well, really ... w and w/o WSDL.)
-- Web Service Description Language
SOAP comes in two flavors(scented and unscented? Nope ...)
WITH and WITHOUT weasels!
(Well, really ... w and w/o WSDL.)
So let's look at without, first.
The Soap "Hello World" example(thanks to://php.net/manual/de/soapserver.construct.php
<?php // Client example
$client = new SoapClient(null, array( 'location' => "http://regmaster3.com/sandbox/soapserver.php",
'uri' => "http://regmaster3.com/sandbox/soapserver.php", 'trace' => 1 ));
echo $return = $client->__soapCall("helloWorld",array("Delighted to be here!"));
?>
Two underscores: a built-in method soapCallThe function of the service to be called
the data to be passed to that service
The Soap "Hello World" example(thanks to://php.net/manual/de/soapserver.construct.php
<?php // Client example
$client = new SoapClient(null, array( 'location' => "http://regmaster3.com/sandbox/soaptut4s.php",
'uri' => "http://regmaster3.com/sandbox/soaptut4s.php", 'trace' => 1 ));
echo $return = $client->__soapCall("helloWorld",array("Delighted to be here!"));
?>
Two underscores: a built-in method soapCallThe function of the service to be called
the data to be passed to that service
The Soap "Hello World" example(thanks to://php.net/manual/de/soapserver.construct.php
<?php // Client example
$client = new SoapClient(null, array( 'location' => "http://regmaster3.com/sandbox/soaptut4s.php",
'uri' => "http://regmaster3.com/sandbox/soaptut4s.php", 'trace' => 1 ));
echo $return = $client->__soapCall("helloWorld",array("Delighted to be here!"));
?>
Two underscores: a built-in method soapCallThe function of the service to be called
the data to be passed to that service
The Soap "Hello World" example(thanks to://php.net/manual/de/soapserver.construct.php
<?php // Server example 'soapserver.php'prototypeclass MyClass { public function helloWorld() {
return 'Hallo Welt you made it! '. print_r(func_get_args(), true); }
} try {
$server = new SOAPServer( NULL, array('uri' => 'http://regmaster3.com/sandbox/soapserver.php' )
); $server->setClass('MyClass');
$server->handle(); // This must be the last action. It "sets the mouse-trap"}
catch (SOAPFault $f) { print $f->faultstring;}
?>
The Soap "Hello World" example(thanks to://php.net/manual/de/soapserver.construct.php
<?php // Server example 'soapserver.php'prototypeclass MyClass { public function helloWorld() {
return 'Hallo Welt you made it! '. print_r(func_get_args(), true); }
} try {
$server = new SOAPServer( NULL, array('uri' => 'http://regmaster3.com/sandbox/soapserver.php' )
); $server->setClass('MyClass');
$server->handle(); // This must be the last action. It "sets the mouse-trap"}
catch (SOAPFault $f) { print $f->faultstring;}
?>
The Soap "Hello World" example(thanks to://php.net/manual/de/soapserver.construct.php
<?php // Server example 'soapserver.php'prototypeclass MyClass { public function helloWorld() {
return 'Hallo Welt you made it! '. print_r(func_get_args(), true); }
} try {
$server = new SOAPServer( NULL, // We discuss when WSDL comes uparray('uri' => 'http://regmaster3.com/sandbox/soapserver.php' )
); $server->setClass('MyClass');
$server->handle(); // This must be the last action. It "sets the mouse-trap"}
catch (SOAPFault $f) { print $f->faultstring;}
?>
Advantages over cURL
1)SOAP does the work of establishing the connection between client & server
2) SOAP communicates via objects, not text files (urlencoding, etc.)
Design Process:
1) Build a synchronous polling version, to reuse my existing code (dumb though it is.)
2) Build an asynchronous polling version – "have you got anything new".
3) Build a PUSH version instead of a Pull-Pull-Pull version
Huh? That is, make the registration system tell the mag printer when to print.Instead of having the mag print ask-ask-ask
Disadvantage of this approach: The mag printer must now offer a public websitewhich can be accessed by the reg system to initiate the transaction.
Moving on to WSDL
Using someone else's service is challenging.
Our 'Hallo Welt' example required that we know exactly what functionsthe service offered. If we got it wrong, the only error message would bea complex stack trace (or nothing, if the server was "buttoned up" for production.
It would be desirable if Web Services were 'self-describing'.
To describe something you need a language. Hence, WSDL
http://devzone.zend.com/2202/php-and-soap-first-steps/
A very nice tutorial
Go through the 'boxing' example using soapUI
berm.co.nz
Moving on to WSDL
Using someone else's service is challenging.
Our 'Hallo Welt' example required that we know exactly what functionsthe service offered. If we got it wrong, the only error message would bea complex stack trace (or nothing, if the server was "buttoned up" for production.
It would be desirable if Web Services were 'self-describing'.
To describe something you need a language. Hence, WSDL
<< Out of time for lesson planning. We peek briefly at WSDL, then adjourn.>>
ASSIGNMENT: Work through the tutorial listed on the previous page.
Be able to explain in your own words, what each element in a WSDL document does.