8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
1/37
Service ComponentArchitecture for PHPReusable components and effort-free web servicesMatthew Peters, IBM Hursley Park
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
2/37
1
Background IBM Hursley Park, Winchester, UK
http://www5.ibm.com/uk/locations/hursley_explore.html
2-3K people
Services, outsourcing
Product development: CICS, MQSeries, Java Incubator group:
Porting, experimenting with technologies from
Java world, implementing and simplifying in PHP
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
3/37
2
How to find us Google for OSOA
(Open Service Oriented Architecture)
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
4/37
3
Agenda Two slide-overview Some simple SCA components (hello worldstyle)
Components calling each other locally Make them all run as web services (Slides and Zend Studio)
More SCA: Interoperability with other web services Exceptions Data Structures
Work in progress: DOJO, JSON-RPC and SCA Summary, Futures and Links
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
5/37
4
SWG AB IncubatorsService Component Architecture
for PHP SCA for PHP allows a PHP programmer to write reusable
components (classes) in PHP, which can be calledeither locally, or remotely via Web Services, with anidentical interface.
Components use PHP annotations both to declare theirdependencies on other components, and to define theinterface which they expose as a service. Business logicis kept separate from interface and dependencies.
Deploying a PHP component as a web service can be as
simple as copying it into a web servers document root.
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
6/37
5
Making your component reusable
Do not entangle the business logic with the wiring
1. Be flexible about how you are called
Expose as many bindings as needed make sure your business logic does notneed to know how it was called
2. Be flexible about your dependencies Declare the dependencies but make sure your business logic does not need to
know how to resolve these Ideally get something else to wire up the components (Inversion of Control;
Dependency Injection patterns)
JSON-RPC binding
A component,containing
business logic
A local component,Same call stack
A web service
2. Be flexible aboutyour dependencies1. Be flexible about
how you are called
Local binding
Web service binding
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
7/37
6
Four scenarios1. One component called locally
2. One component calling two others3. Make the single component expose aWeb service binding
4. Make them all use web services
Same interface, minimal effort
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
8/37
7
Scenario 1. Simplest A client script calling one local
component What does the simplest SCA componentlook like?
GreetingComponentclient
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
9/37
8
Our first simple SCA component A PHP class
@service annotation include for SCA.php
GreetingComponent
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
10/37
9
Calling an SCA component from a
client script Client script
Includes SCA.php But is not itself a
component Uses SCA::getService()
getService takes apath
Absolute or relative
Relative paths areresolved against thelocation of the script
getService returns aproxy object:
Enforces pass-by-
value
GreetingComponent
client
"hello PHP"
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
11/37
10
Scenario 2. Multiple A local component calling other local
components How are the dependencies wired up?
ReversingComponent
ReversedGreetingComponent
GreetingComponent
client
"PHP olleh"
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
12/37
11
Add a second component Like GreetingComponent:
@service
Include for SCA.php
ReversingComponent
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
13/37
12
Dependencies Dependencies are declared annotated with @reference
The instance variable
following will be assigned aproxy Hence needs to be public Initialised before any
business logic
@binding.php
indicates how to find thecomponent and that it is local same rules as getService
ReversedGreetingComponent
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
14/37
13
What have we got so far? Sample call stack:
ReversingComponent
ReversedGreetingComponent
GreetingComponent
client
reverse( $in ) C:\Program Files\Apache Group\Apache2\htdocs\Konferenz\ReversingComponent.php line 13__call( $method_name, $arguments ) c:\php\PEAR\SCA\SCA_LocalProxy.php line 109greet( $name ) C:\Program Files\Apache Group\Apache2\htdocs\Konferenz\ReversedGreetingComponent.php line 24
__call( $method_name, $arguments ) c:\php\PEAR\SCA\SCA_LocalProxy.php line 109main( ) C:\Program Files\Apache Group\Apache2\htdocs\Konferenz\client2.php line 7
SCA_Localproxy
breakpoint
"PHP olleh"
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
15/37
14
Scenario 3. Web Service A client script calling one remote
component How to expose a web service binding
GreetingComponentclient
= SOAP Web service request/response
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
16/37
15
Exposing a web service binding @binding
Expose a web servicebinding
Public methods are in theinterface
@param/@return Need more information
about each method
GreetingComponent
= SOAP Web service request/response
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
17/37
16
Generating the WSDL Generated in response to HTTP GET with ?wsdl
http://www.example.com/GreetingComponent.php?wsdl
Do it in a browser file_get_contents('http://www.example.com/GreetingCom
ponent.php?wsdl');
Currently cached in the same directory as the
component http://www.example.com/GreetingComponent.wsdl
(in future need to do something different to avoidneed for write access into htdocs)
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
18/37
17
Generated WSDL
Document/literalwrapped style Message
formats areexplicit withinthe schema
...
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
19/37
18
Generated WSDL message
post binding
...
...
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
20/37
19
Generated WSDL Location attribute is decided once the file is in place
Currently using the URL to determine the location with respect to thedocument root
(in future need to do something different to cope with proxies,rewriting, firewalls)
Ends with a distinctive comment Special handling of exceptions when one component talks to another
...
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
21/37
20
Calling a remote SCA component from
a script SCA::getService() takes the
location of the WSDL Once again, $service is a
proxy: SCA_SoapProxy Proxy contains within it an
instance of the ext/SOAPclient
Location can be a URL In which case the soap
extension will probablycache it
Location can be a path Relative paths resolved
against location of script
Greeting
Componentclient
= SCA_SoapProxy
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
22/37
21
Sample Soap request Document/literal wrapped, so
element enclosing element
PHP
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
23/37
22
Scenario 4. Multiple web service Everything separated
ReversingComponent
ReversedGreetingComponent
GreetingComponent
client
= SOAP Web service request/response
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
24/37
23
A second remote component Annotations
@binding @param @return
And generate WSDL asbefore
ReversingComponent
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
25/37
24
Remote dependencies
@binding.ws
for remotecomponent
locates wsdl
ReversedGreetingComponent
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
26/37
25
What have we got now? What have we achieved? Client local local Client remote remote
What had to change? Arguments to getService(), or @binding.php to @binding.ws Annotatations to describe the interface in more detail Generating WSDL on demand; otherwise deployment is just copying the component
But the business logic remains unchanged
ReversingComponent
ReversedGreetingComponent
GreetingComponent
client
SOAP Web service request/response
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
27/37
26
Interlude But, you have to change the files
themselves True, but changing an annotation in an interpretedfile is that different from a line in a config file?
Essential point is that wiring and business
logic are separated Same file, but in different worlds Wiring is declarative, in annotations Business logic is imperative, in code
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
28/37
38
Futures Annotation overriding
Changing service targets, bindings,properties from outside
PHP classes rather than xsds for datastructures
Simple database services
Other bindings
Atompub, REST (XML and JSON), RSS
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
29/37
39
DOJO, JSON-RPC and SCA DOJO is a user interface widget set written in JavaScript Can talk back to the server asynchronously - AJAX style Can use JSON-RPC to do so
JSON = JavaScript Object Notation Like a simplified XML Name/value pairs { for structure [ array
A JSON-RPC interface can be defined in SMD = Service Method Description
Like a simplified WSDL Also written in JSON
SCA components can expose a JSON-RPC binding too
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
30/37
40
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
31/37
41
A component exposing a JSON
binding @binding.jsonrpc
Generates .smd
?smd
smd = service methoddescription
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
32/37
42
HelloService.php?smd Defines a service that has:
One method sayHello(), with
One parameter, name{"SMDVersion":".1","serviceType":"JSON-RPC","serviceURL":"http://localhost/Samples/JsonRpc/hello/HelloService.php",
"methods": [ {"name":"sayHello","parameters": [ {
"name":"name","type":"string
} ],"return": {"type":"string"}
} ]}
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
33/37
43
A DOJO function to call sayHello
Obtain .smd
Issue the call
function sayHello(){
var SCA = new dojo.rpc.JsonService({smdUrl: "HelloService.php?smd"});var inputfield = document.getElementById("hellotext").value;SCA.sayHello(inputfield).addCallback(handleResponse);
}
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
34/37
44
JSON-RPC - POST POST Style - Request
POST Style - Response
POST /json-rpc/HelloService.php HTTP/1.1
Host: localhost:8081
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/json-rpc
Content-Length: 48
Pragma: no-cache
Cache-Control: no-cache
{"params":["Hello!"],"method":"sayHello","id":1}
HTTP/1.1 200 OK
Date: Tue, 03 Oct 2006 18:14:35 GMT
Server: Apache/2.0.55 (Win32) PHP/5.2.0RC5-dev
X-Powered-By: PHP/5.2.0RC5-dev
Content-Length: 27
Keep-Alive: timeout=15, max=89
Connection: Keep-Alive
Content-Type: application/json-rpc
{return":"Hello "}
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
35/37
45
Links
SCA for PHP homepage http://osoa.org/display/PHP/SOA+PHP+Homepage
Discussion Group http://groups.google.com/group/phpsoa/
Blog http://www.ibm.com/developerworks/blogs/page/phpblog
SDO for PHP
http://www.php.net/sdo
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
36/37
46
Acknowledgements
Other members of the SCA for PHP team
Graham Charters, Megan Beynon, ChrisMiller, Caroline Maynard, Simon Laws
Special thanks to Dmitry Stogov for help
with the SOAP extension, serialising andde-serialising SDOs
8/14/2019 Service Component Architecture for PHP Konferenz 2006 begin end
37/37
47
The end