0
CIS5930 Internet Computing XML Web Services Basics Prof. Robert van Engelen
Web Services Basics <ul><li>Interoperability has highest priority </li></ul><ul><ul><li>XML over HTTP </li></ul></ul><ul><...
XML Web Services Protocols <ul><li>SOAP </li></ul><ul><ul><li>“ Simple Object Access Protocol” is an XML messaging protoco...
WSDL <ul><li>WSDL represents a contract between the service requestor and the service provider </li></ul><ul><li>WSDL is a...
WSDL Specification <ul><li>The  definitions  root element defines the name and namespace of the web service </li></ul><ul>...
Example WSDL <ul><li>The HelloService service provides a single publicly available function sayHello </li></ul><ul><li>The...
WSDL definition Root Element <ul><li>Defines the name and targetNamespace: <definitions name=&quot;HelloService”  targetNa...
The WSDL message Elements <ul><li>Two message elements are defined </li></ul><ul><li>The first represents a request messag...
Built-in XSD SimpleTypes Simple type Example Value(s) string Web Services boolean true, false, 1, 0 float -INF, -1E4, -0, ...
The WSDL portType Element <ul><li>The portType element defines a single operation, sayHello </li></ul><ul><li>The operatio...
Message Exchange Patterns <ul><li>The operation in portType uses input and/or output to define the message exchange patter...
The WSDL binding Element <ul><li>The binding element provides specific details on how a portType operation will actually b...
WSDL SOAP Bindings <ul><li>WSDL 1.1 includes built-in extensions for SOAP 1.1 <binding name=&quot;Hello_Binding&quot; type...
WSDL SOAP Bindings (cont’d) <ul><li>The  soap:binding  element indicates a SOAP binding over HTTP transport </li></ul><ul>...
SOAP Request Message <ul><li>An RPC request message uses the  encodingStyle  and  namespace : <?xml version='1.0' encoding...
SOAP Response Message <ul><li>An RPC request message: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope    xmlns:S...
Using WSDL <ul><li>Most Web service development toolkits support WSDL </li></ul><ul><ul><li>Generate WSDL from server (int...
Generating WSDL and Server Code with gSOAP <ul><li>Suppose we implement a HelloService with one operation sayHello that ta...
Implementing a Web Service with gSOAP <ul><li>Add directives to the header file specification to define the service name, ...
Implementing a Web Service with gSOAP (cont’d) <ul><li>The following files are generated: soapStub.h annotated copy of the...
Implementing a Web Service with gSOAP (cont’d) <ul><li>Implementation of the sayHello function in hello.c: int ns__sayHell...
Implementing a Web Service with gSOAP (cont’d) <ul><li>Deploy hello.cgi as a service in Apache (e.g. cgi-bin dir) and publ...
Implementing a Concurrent Web Service with gSOAP <ul><li>#include “hello.nsmap” int main() { pthread_t tid;   struct soap ...
Implementing a Client with gSOAP <ul><li>Since we already have a gSOAP header file with the service definitions, we can al...
Implementing a Service with ASP.NET in VB <ul><li><%@ WebService Language=&quot;VB&quot; Class=&quot;TempConvert&quot; %> ...
Implementing a Client with SOAP::Lite for Perl <ul><li>Example in Perl using the SOAP::Lite package: use SOAP::Lite;   pri...
SOAP Fault messages <ul><li>The gSOAP service may return a  SOAP Fault :   return soap_sender_fault(soap, “ description ”,...
SOAP 1.1 Faults <ul><li>The SOAP Fault element has the following sub elements: </li></ul><ul><ul><li><faultcode> A code fo...
WSDL and SOAP Faults <ul><li>Faults in portType operations specify which faults may be returned: <message name=&quot;Authe...
SOAP Headers <ul><li>The optional  SOAP Header  element contains SOAP processing information in one or more subelements, s...
SOAP Headers (cont’d) <ul><li>The optional actor attribute may be used to address the Header element to a particular endpo...
SOAP Headers (cont’d) <ul><li>The SOAP Header is a struct in gSOAP, defined in the header file: #import “wsse.h” // get WS...
SOAP RPC Encoding <ul><li>SOAP RPC encoding defines rules on representing primitive types, xs:simpleTypes (e.g. enumeratio...
SOAP RPC Encoding (cont’d) <ul><li>Primitive types </li></ul><ul><ul><li>Built-in XSD types, such as xs:string (see Schema...
SOAP RPC Encoding (cont’d) <ul><li>Arrays are “SOAP encoded” arrays:   <xs:complexType name=&quot;ArrayOfstring&quot;>   <...
SOAP RPC Encoding (cont’d) <ul><li>Struct are just xs:complexTypes with xs:sequence (or xs:all):   <xs:complexType name=”l...
RPC versus Doc/lit in WSDL <ul><li>Document/literal SOAP messages don’t include encodingStyle and XML types for request/re...
RPC versus Doc/lit in WSDL (cont’d) <ul><li>The parts in messages now refer to elements, which will be the request/respons...
RPC versus Doc/lit in WSDL (cont’d) <ul><li>The parts in messages refer to elements that define the request and response e...
SOAP Request Message in Doc/Lit Style <ul><li>Note the absence of SOAP-ENC:encodingStyle and xsi:type in the message: <?xm...
SOAP Multi-ref Encoding <ul><li>SOAP operation (request/response) </li></ul><ul><li>The XSD  type system  to represent val...
Static Structure Analysis for SOAP RPC Encoding <x>   <x  href =“#456”/>   …   <x  href =“#456”/>   … </x> … <mref  id =“4...
gSOAP Constructs a Plausible Object Model for Serialization typedef int SSN; struct Node {   int val;   int *ptr;   float ...
Generating an XML Schema Definition for Serialized XML val ptr num next Node SSN <simpleType name=“SSN”>   <restriction ba...
Generating Code for Runtime Points-To Analysis serialize_pointerToint(int *p) { if (p != NULL)   { // lookup and mark (p,T...
Generating Serialization Code put_pointerToint(int *p) { if (p != NULL)   { // lookup (p,TYPE_int)   // if  embedded , the...
Serialization Example val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A...
Deserialization Example <Node id=“_1”>   </Node> val =? ptr =? num =? next =? Node id=1 Recursive descent parsing with obj...
Deserialization Example (cont’d) val =123 ptr =? num =? next =? Node <Node id=“_1”>   <val>123</val>   </Node> id=1 Recurs...
Deserialization Example (cont’d) val =123 ptr =? num =? next =? Node <Node id=“_1”>   <val>123</val>   <ptr ref=“#_2”/>   ...
Deserialization Example (cont’d) val =123 ptr =? num =1.4 next =? Node <Node id=“_1”>   <val>123</val>   <ptr ref=“#_2”/> ...
Deserialization Example (cont’d) val =123 ptr =? num =1.4 next =B Node val =? ptr =? num =? next =? Node <Node id=“_1”>   ...
Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B Node val =456 ptr =? num =? next =? Node <Node id=“_1”> ...
Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node val =456 ptr =C num =? next =? Node <Node id=“...
Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node SSN val =456 ptr =C num =2.3 next =? Node <Nod...
Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node SSN val =456 ptr =C num =2.3 next =A Node <Nod...
Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node SSN val =456 ptr =C num =2.3 next =A Node <Nod...
Converting a WSDL to Code with gSOAP <ul><li>The wsdl2h tool converts a (set of) WSDL files and schemas to a header file <...
WS-* Protocols and Plugins
SOAP With MTOM Attachments <ul><li>Raw binary data can be transported in a SOAP message as base64 </li></ul><ul><li>MTOM (...
SOAP With MTOM Attachments (cont’d) <ul><li>Example HTTP body with SOAP message and MTOM attachment: --mimeboundary Conten...
WS-Addressing <ul><li>WS-Addressing is a Web services protocol for routing messages (request, response, and faults) </li><...
WS-Addressing (cont’d) <ul><li>WS-Addressing header elements within the SOAP Header: </li></ul><ul><ul><li><wsa:MessageID>...
WS-Security <ul><li>WS-Security provides  message-level security </li></ul><ul><ul><li>HTTPS provides end-to-end transport...
Username Token <ul><li>The Username token security header in wsse:Security contains a username and password in plain text ...
Security Timestamps <ul><li>A timestamp can be included to define the lifetime of a message </li></ul><ul><li>The timestam...
Signatures <ul><li>The wsse:BinarySecurityToken contains the public key </li></ul><ul><li>The ds:Signature element contain...
Signature Example <wsse:Security>   <wsse:BinarySecurityToken …> … </wsse:BinarySecurityToken>   <ds:Signature>   <ds:Sign...
List of WS-* Protocols <ul><li>Messaging </li></ul><ul><ul><li>SOAP </li></ul></ul><ul><ul><li>SOAP with Attachments  (SwA...
List of WS-* Protocols <ul><li>Directory access and discovery </li></ul><ul><ul><li>UDDI  (Universal Description, Discover...
Other Notable WS-* Protocols <ul><li>Managing resources:  Web Services Resource Framework  (WSRF) </li></ul><ul><ul><li>WS...
Other Notable WS-* Protocols <ul><li>Device Profile for Web Services  (DPWS) </li></ul><ul><ul><li>Goals similar to univer...
To be continued…
Upcoming SlideShare
Loading in...5
×

XML and SOAP Web Services

9,791

Published on

1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
9,791
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
564
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "XML and SOAP Web Services"

  1. 1. CIS5930 Internet Computing XML Web Services Basics Prof. Robert van Engelen
  2. 2. Web Services Basics <ul><li>Interoperability has highest priority </li></ul><ul><ul><li>XML over HTTP </li></ul></ul><ul><ul><li>Web services can be created regardless of the programming language </li></ul></ul><ul><li>Reusable application components </li></ul><ul><ul><li>Software can be reused as service components in a service-oriented architecture, i.e. to support the requirements of software users </li></ul></ul><ul><ul><li>Compositionality is realized with open standards </li></ul></ul><ul><li>Connect existing software </li></ul><ul><ul><li>Publish the application as a service </li></ul></ul><ul><ul><li>Applications connect and interact by encoding and decoding data in XML </li></ul></ul>
  3. 3. XML Web Services Protocols <ul><li>SOAP </li></ul><ul><ul><li>“ Simple Object Access Protocol” is an XML messaging protocol </li></ul></ul><ul><ul><li>Typically remote procedure call (RPC) request-response messages </li></ul></ul><ul><ul><li>Or XML-based messages (document/literal style) </li></ul></ul><ul><li>WSDL </li></ul><ul><ul><li>“ Web Service Description Language” is an XML document that defines the service interface, protocol bindings, and service endpoint addresses </li></ul></ul><ul><ul><li>Uses XML schema to define XML types </li></ul></ul><ul><ul><li>Typically uses SOAP to bind the messaging protocol </li></ul></ul><ul><li>UDDI </li></ul><ul><ul><li>“ Universal Description, Discovery and Integration” is a repository/database of services (e.g. defined by WSDLs) </li></ul></ul><ul><ul><li>Not very popular, won’t discuss </li></ul></ul>
  4. 4. WSDL <ul><li>WSDL represents a contract between the service requestor and the service provider </li></ul><ul><li>WSDL is an XML specification that defines four critical pieces of information of an XML Web service: </li></ul><ul><ul><li>Interface information describing all publicly available functions </li></ul></ul><ul><ul><li>Data type information for all message requests and message responses </li></ul></ul><ul><ul><li>Binding information about the transport protocol to be used </li></ul></ul><ul><ul><li>Address information for locating the specified service </li></ul></ul>
  5. 5. WSDL Specification <ul><li>The definitions root element defines the name and namespace of the web service </li></ul><ul><li>The types element contains a set of XML schemas with all the data types (XML elements and types) used between the client and server </li></ul><ul><li>One or more message elements define the names of the messages, each contains zero or more message part elements, which can refer to message parameters or message return values </li></ul><ul><li>The portType element combines multiple message elements to form a complete one-way or round-trip operation </li></ul><ul><li>The binding element describes how the service will be implemented on the wire </li></ul><ul><li>The service element defines the endpoint address for invoking the service </li></ul>
  6. 6. Example WSDL <ul><li>The HelloService service provides a single publicly available function sayHello </li></ul><ul><li>The function expects a single string parameter, and returns a single string greeting </li></ul><ul><li>Request-response message pattern over HTTP using HTTP POST </li></ul>
  7. 7. WSDL definition Root Element <ul><li>Defines the name and targetNamespace: <definitions name=&quot;HelloService” targetNamespace=&quot;http://www.ecerami.com/wsdl/HelloService.wsdl” xmlns=&quot;http://schemas.xmlsoap.org/wsdl/” xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/” xmlns:tns=&quot;http://www.ecerami.com/wsdl/HelloService.wsdl” xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema”> </li></ul><ul><li>Typically the xmlns namespace bindings are included in the root element and are used in the remainder of the WSDL </li></ul><ul><li>Note that the WSDL namespace is declared as the default namespace for all of the other WSDL elements ( http://schemas.xmlsoap.org/wsdl/ ) so these elements are not explicitly namespace qualified </li></ul>
  8. 8. The WSDL message Elements <ul><li>Two message elements are defined </li></ul><ul><li>The first represents a request message, SayHelloRequest, and the second represents a response message, SayHelloResponse: <message name=&quot;SayHelloRequest&quot;> <part name=&quot;firstName&quot; type=&quot;xsd:string&quot;/> </message> <message name=&quot;SayHelloResponse&quot;> <part name=&quot;greeting&quot; type=&quot;xsd:string&quot;/> </message> </li></ul><ul><li>For the request, the part specifies the function parameters </li></ul><ul><li>For the response, the part specifies the function return values </li></ul><ul><li>The type is a QName value, indicating the schema type of the part </li></ul>
  9. 9. Built-in XSD SimpleTypes Simple type Example Value(s) string Web Services boolean true, false, 1, 0 float -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN double -INF, -1E4, -0, 0, 12.78E-2, 12, INF, NaN decimal -1.23, 0, 123.4, 1000.00 integer -126789, -1, 0, 1, 126789 nonPositiveInteger -126789, -1, 0 negativeInteger -126789, -1 long -1, 12678967543233 int -1, 126789675 short -1, 12678 byte -1, 126 nonNegativeInteger 0, 1, 126789 unsignedLong 0, 12678967543233 unsignedInt 0, 1267896754 unsignedShort 0, 12678 unsignedByte 0, 126 positiveInteger 1, 126789 date 1999-05-31 time 13:20:00.000, 13:20:00.000-05:00
  10. 10. The WSDL portType Element <ul><li>The portType element defines a single operation, sayHello </li></ul><ul><li>The operation consists of a single input message (SayHelloRequest) and a single output message (SayHelloResponse): <portType name=&quot;Hello_PortType&quot;> <operation name=&quot;sayHello&quot;> <input message=&quot;tns:SayHelloRequest&quot;/> <output message=&quot;tns:SayHelloResponse&quot;/> </operation> </portType> </li></ul><ul><li>The input/output elements specify a message attribute of tns:SayHelloRequest or tns:SayHelloResponse </li></ul><ul><li>The tns prefix references the targetNamespace defined within the definitions element </li></ul>
  11. 11. Message Exchange Patterns <ul><li>The operation in portType uses input and/or output to define the message exchange pattern </li></ul><ul><li>WSDL supports four basic patterns of operation </li></ul><ul><ul><li>One-way </li></ul></ul><ul><ul><li>Request-response </li></ul></ul><ul><ul><li>Solicit-response </li></ul></ul><ul><ul><li>Notification </li></ul></ul><ul><li>The one-way and request-response are most often used </li></ul>
  12. 12. The WSDL binding Element <ul><li>The binding element provides specific details on how a portType operation will actually be transmitted over the wire </li></ul><ul><li>Bindings can be made available via multiple transports </li></ul><ul><li>Multiple bindings for a single portType can be specified </li></ul><ul><li>The binding element itself specifies name and type attributes: <binding name=&quot;Hello_Binding&quot; type=&quot;tns:Hello_PortType&quot;> </li></ul><ul><li>The type attribute references the portType </li></ul>
  13. 13. WSDL SOAP Bindings <ul><li>WSDL 1.1 includes built-in extensions for SOAP 1.1 <binding name=&quot;Hello_Binding&quot; type=&quot;tns:Hello_PortType&quot;> </li></ul><ul><li><soap:binding style=&quot;rpc&quot; transport=&quot;http://schemas.xmlsoap.org/soap/http&quot;/> <operation name=&quot;sayHello&quot;> <soap:operation soapAction=&quot;sayHello&quot;/> <input> <soap:body encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/” namespace=&quot;urn:examples:helloservice” use=&quot;encoded&quot;/> </input> <output> <soap:body encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/” namespace=&quot;urn:examples:helloservice” use=&quot;encoded&quot;/> </output> </operation> </binding> </li></ul>
  14. 14. WSDL SOAP Bindings (cont’d) <ul><li>The soap:binding element indicates a SOAP binding over HTTP transport </li></ul><ul><ul><li>The style attribute indicates rpc for an RPC format or document for a document-oriented message format </li></ul></ul><ul><ul><li>The transport attribute defines the transport mechanism </li></ul></ul><ul><li>The soap:operation element indicates the binding of a specific operation to a SOAP implementation </li></ul><ul><ul><li>The soapAction attribute specifies that the SOAPAction HTTP header should be used for identifying the service (SOAP 1.1 only) </li></ul></ul><ul><li>The soap:body element specifies the details of the input and output messages </li></ul><ul><ul><li>The encodingStyle attribute defines the encoding format when the use attribute is encoded (RPC encoded) and the namespace attribute defines the RPC message namespace </li></ul></ul><ul><ul><li>For document/literal messaging, the use attribute is literal </li></ul></ul>
  15. 15. SOAP Request Message <ul><li>An RPC request message uses the encodingStyle and namespace : <?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance’ xmlns:xsd='http://www.w3.org/2001/XMLSchema’ xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/’ xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/’ soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> <soap:Body> <n:sayHello xmlns:n='urn:examples:helloservice'> <firstName xsi:type='xsd:string'>World</firstName> </n:sayHello> </soap:Body> </soap:Envelope> </li></ul>
  16. 16. SOAP Response Message <ul><li>An RPC request message: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/’ xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance’ xmlns:xsd='http://www.w3.org/1999/XMLSchema'> <SOAP-ENV:Body> <ns1:sayHelloResponse xmlns:ns1='urn:examples:helloservice' SOAP-ENV:encodingStyle= 'http://schemas.xmlsoap.org/soap/encoding/'> <greeting xsi:type='xsd:string'>Hello, World!</greeting> </ns1:sayHelloResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> </li></ul>
  17. 17. Using WSDL <ul><li>Most Web service development toolkits support WSDL </li></ul><ul><ul><li>Generate WSDL from server (interface) code </li></ul></ul><ul><ul><li>Translate WSDL to server objects and client proxies </li></ul></ul><ul><li>Dynamic invocation obtains the WSDL, select an operation, populate the parameters and send the request message </li></ul><ul><ul><li>Generic SOAP client: http://www.soapclient.com/soaptest.html </li></ul></ul><ul><ul><li>http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl </li></ul></ul><ul><li>Find more WSDLs and code at http://www.xmethods.com </li></ul>
  18. 18. Generating WSDL and Server Code with gSOAP <ul><li>Suppose we implement a HelloService with one operation sayHello that takes a string parameter s and returns the string “Hello s ” </li></ul><ul><li>To bind XML namespaces to C (and C++) code, gSOAP uses a prefix convention for function names and type names: prefix_ _name </li></ul><ul><li>The service interface is defined in a header file containing the line: int ns__sayHello(char *firstName, char **greeting); </li></ul><ul><li>To generate WSDL and server code (-S) or client code (-C) in C (-c) for SOAP RPC encoding (-e): $ soapcpp2 -S -c -e hello.h </li></ul>input output
  19. 19. Implementing a Web Service with gSOAP <ul><li>Add directives to the header file specification to define the service name, namespace, and endpoint: //gsoap ns service name: hello //gsoap ns service namespace: urn:hello //gsoap ns service location: http://www.cs.fsu.edu/~engelen/hello.cgi int ns__sayHello(char *firstName, char **greeting); </li></ul>
  20. 20. Implementing a Web Service with gSOAP (cont’d) <ul><li>The following files are generated: soapStub.h annotated copy of the header file soapH.h XML serializer declarations soapC.c XML serializers for C/C++ types soapServer.c SOAP server skeleton and dispatcher hello.nsmap XML namespace mapping table hello.wsdl the service WSDL hello.sayHello.req.xml sample request message hello.sayHello.res.xml sample response message </li></ul><ul><li>To complete the service, we create a C implementation of the sayHello function with the following parameters: int ns__sayHello(struct soap *soap, char *firstName, char **greeting); </li></ul><ul><li>The first arg is the gSOAP engine context (runtime environment) </li></ul>
  21. 21. Implementing a Web Service with gSOAP (cont’d) <ul><li>Implementation of the sayHello function in hello.c: int ns__sayHello(struct soap *soap, char *firstName, char **greeting) { if (!firstName) return soap_sender_fault(soap, “No name!”, NULL); *greeting = (char*)soap_malloc(soap, strlen(firstName)+8); strcpy(*greeting, “Hello ”); strcat(*greeting, firstName); strcat(*greeting, “!”); return SOAP_OK; } </li></ul><ul><li>For a simple CGI-based service, add the service dispatcher: #include “hello.nsmap” int main() { return soap_serve(soap_new()); } </li></ul><ul><li>Compile with gcc -o hello.cgi hello.c stdsoap2.c soapC.c soapServer.c </li></ul>
  22. 22. Implementing a Web Service with gSOAP (cont’d) <ul><li>Deploy hello.cgi as a service in Apache (e.g. cgi-bin dir) and publish hello.wsdl on the Web site </li></ul><ul><li>To test the service over stdin/stdout, modify hello.sayHello.req.xml to include a name string and run hello.cgi from the command line: $ ./hello.cgi < hello.sayHello.req.xml </li></ul><ul><li>To deploy as an iterative stand-alone service, use the following: #include “hello.nsmap” int main() { struct soap *soap = soap_new(); soap_bind(soap, NULL, 8080, 100); for (;;) { if (soap_accept(soap) < 0) break; soap_serve(soap); soap_destroy(soap); soap_end(soap); } soap_print_fault(soap, stderr); soap_done(soap); free(soap); return 0; } </li></ul>
  23. 23. Implementing a Concurrent Web Service with gSOAP <ul><li>#include “hello.nsmap” int main() { pthread_t tid; struct soap *soap = soap_new(); soap_bind(soap, NULL, 8080, 100); for (;;) { if (soap_accept(soap) < 0) break; pthread_create(&tid,NULL,(void*(*)(void*))serve,(void*)soap_copy(soap)); } soap_print_fault(soap, stderr); soap_done(soap); free(soap); return 0; } void *serve(void *soap) { pthread_detach(pthread_self()); soap_serve((struct soap*)soap); soap_destroy((struct soap*)soap); soap_end((struct soap*)soap); soap_done((struct soap*)soap); free(soap); return NULL; } int ns__sayHello(struct soap *soap, char *firstName, char **greeting) { … } </li></ul>
  24. 24. Implementing a Client with gSOAP <ul><li>Since we already have a gSOAP header file with the service definitions, we can also create a client from it: $ soapcpp2 -C -c -e hello.h </li></ul><ul><li>The client uses the stub call defined in soapClient.c: #include “hello.nsmap” int main() { struct soap *soap = soap_new(); char *s; if (soap_call_ns__sayHello(soap, NULL, NULL, “Robert”, &s)) soap_print_fault(soap, stderr); else printf(“The response is %s ”, s); soap_destroy(soap); soap_end(soap); soap_done(soap); free(soap); return 0; } </li></ul><ul><li>Compile with gcc -o client client.c stdsoap2.c soapC.c soapClient.c </li></ul>
  25. 25. Implementing a Service with ASP.NET in VB <ul><li><%@ WebService Language=&quot;VB&quot; Class=&quot;TempConvert&quot; %> Imports System Imports System.Web.Services Public Class TempConvert :Inherits WebService <WebMethod()> Public Function FahrenheitToCelsius (ByVal Fahrenheit As Int16) As Int16 Dim celsius As Int16 celsius = ((((Fahrenheit) - 32) / 9) * 5) Return celsius End Function <WebMethod()> Public Function CelsiusToFahrenheit (ByVal Celsius As Int16) As Int16 Dim fahrenheit As Int16 fahrenheit = ((((Celsius) * 9) / 5) + 32) Return fahrenheit End Function End Class </li></ul>
  26. 26. Implementing a Client with SOAP::Lite for Perl <ul><li>Example in Perl using the SOAP::Lite package: use SOAP::Lite;   print &quot;Connecting to Hello Service... &quot;; print SOAP::Lite -> service('http://www.cs.fsu.edu/~engelen/hello.wsdl') -> sayHello ('World'); </li></ul><ul><li>The program generates the following output: Connecting to Hello Service... Hello World! </li></ul>
  27. 27. SOAP Fault messages <ul><li>The gSOAP service may return a SOAP Fault : return soap_sender_fault(soap, “ description ”, detail ); </li></ul><ul><li>If the problem is at the receiving side (SOAP-ENV:Server) use: return soap_receiver_fault(soap, “ description ”, detail ); </li></ul><ul><li>Example SOAP Fault message: HTTP/1.1 500 Internal Server Error Server: gSOAP/2.7 Content-Type: text/xml; charset=utf-8 Content-Length: 520 Connection: close <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/” xmlns:SOAP-ENC=&quot;http://schemas.xmlsoap.org/soap/encoding/” xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema” xmlns:ns=&quot;urn:hello&quot;> <SOAP-ENV:Body SOAP-ENV:encodingStyle=&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Client</faultcode> <faultstring>No name!</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope> </li></ul>
  28. 28. SOAP 1.1 Faults <ul><li>The SOAP Fault element has the following sub elements: </li></ul><ul><ul><li><faultcode> A code for identifying the fault </li></ul></ul><ul><ul><li><faultstring> A human readable explanation of the fault </li></ul></ul><ul><ul><li><faultactor> Information about who caused the fault to happen (opt) </li></ul></ul><ul><ul><li><detail> Holds application specific error information </li></ul></ul><ul><li>The faultcode values defined below must be used in the faultcode element when describing faults: </li></ul><ul><ul><li>VersionMismatch: Invalid namespace for the SOAP Envelope element </li></ul></ul><ul><ul><li>MustUnderstand: An immediate child element of the Header element, with the mustUnderstand attribute set to &quot;1&quot;, was not understood </li></ul></ul><ul><ul><li>Client: Message was incorrectly formed or contained incorrect info </li></ul></ul><ul><ul><li>Server: There was a problem with the server and processing could not proceed </li></ul></ul><ul><li>Note: SOAP 1.2 differs slightly (mostly element naming) </li></ul>
  29. 29. WSDL and SOAP Faults <ul><li>Faults in portType operations specify which faults may be returned: <message name=&quot;AuthenticationFault&quot;> <part name=&quot;AuthenticationFault” element=”f:AuthenticationFault&quot;/> </message> <portType name=“myPort”> <operation name=“getStatus”> <input message=“tns:getStatusRequest”/> <output message=“tns:getStatusResponse”/> <fault name=“fault” message=“tns:AthenticiationFault”/> </operation> </portType> <binding name=“myBinding” type=“myPort”> <operation name=&quot;getStatus&quot;> <wsdl:input> <soap:body use=&quot;literal&quot;/> </wsdl:input> <wsdl:output> <soap:body use=&quot;literal&quot;/> </wsdl:output> <wsdl:fault name=&quot;AuthenticationFault&quot;> <soap:fault name=&quot;AuthenticationFault&quot; use=&quot;literal&quot;/> </wsdl:fault> </operation> </binding> </li></ul>
  30. 30. SOAP Headers <ul><li>The optional SOAP Header element contains SOAP processing information in one or more subelements, such as addressing and authentication, for example: <SOAP-ENV:Envelope …> <SOAP-ENV:Header> <wsse:Security SOAP-ENV:mustUnderstand=&quot;1&quot;> <wsse:UsernameToken wsu:Id=&quot;User&quot;> <wsse:Username>engelen</wsse:Username> <wsse:Password Type=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest&quot;>/u5faawcfIeve1yHCsdXAWyIlbU=</wsse:Password> <wsse:Nonce>NDU0MGE5YjljYTUzYzAzZjA2MTc=</wsse:Nonce> <wsu:Created>2006-10-26T12:27:37Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </SOAP-ENV:Header> <SOAP-ENV:Body> … </SOAP-ENV:Body> </SOAP-ENV:Envelope> </li></ul>
  31. 31. SOAP Headers (cont’d) <ul><li>The optional actor attribute may be used to address the Header element to a particular endpoint: <SOAP-ENV:Header> <m:Transaction SOAP-ENV:actor=” endpoint URL ” SOAP-ENV:mustUnderstand=“1”> … </m:Transaction> <wsse:Security>…</wsse:Security> </SOAP-ENV:Header> </li></ul><ul><li>This allows the header information to be targeted at any intermediate SOAP processors for which this information is intended </li></ul><ul><li>The SOAP mustUnderstand attribute is used to indicate whether a header entry is mandatory or optional for the recipient to process </li></ul>
  32. 32. SOAP Headers (cont’d) <ul><li>The SOAP Header is a struct in gSOAP, defined in the header file: #import “wsse.h” // get WSSE Security elements struct SOAP_ENV__Header { mustUnderstand _m__Transaction *m__Transaction; mustUnderstand _wsse__Security *wsse__Security; }; and accessible in the soap context, for example: soap.header.m__Transaction = new _m__Transaction(); </li></ul>
  33. 33. SOAP RPC Encoding <ul><li>SOAP RPC encoding defines rules on representing primitive types, xs:simpleTypes (e.g. enumerations), array, and records (structs) as xs:complexTypes in XML </li></ul><ul><li>Closer to the notion of programming language types </li></ul><ul><li>Full XML schema support is not possible </li></ul><ul><ul><li>XML attributes not supported </li></ul></ul><ul><ul><li>No element repetitions with maxOccurs=“unbounded” </li></ul></ul><ul><ul><li>Only xs:sequence and xs:all, no xs:choice </li></ul></ul>
  34. 34. SOAP RPC Encoding (cont’d) <ul><li>Primitive types </li></ul><ul><ul><li>Built-in XSD types, such as xs:string (see Schema specification) </li></ul></ul><ul><ul><li>Schema xs:simpleTypes for elements, such as enumerations <xs:simpleType name=”switch&quot;> <xs:restriction base=&quot;xsd:token&quot;> <xs:enumeration value=”on&quot;/> <xs:enumeration value=”off&quot;/> </xs:restriction> </xs:simpleType> </li></ul></ul><ul><ul><li>Base64 (xs:base64Binary) and hex (xs:hexBinary) types </li></ul></ul>
  35. 35. SOAP RPC Encoding (cont’d) <ul><li>Arrays are “SOAP encoded” arrays: <xs:complexType name=&quot;ArrayOfstring&quot;> <xs:complexContent> <xs:restriction base=&quot;SOAP-ENC:Array&quot;> <xs:sequence> <xs:element name=&quot;item&quot; type=&quot;xsd:string” minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded”/> </xs:sequence> <xs:attribute ref=&quot;SOAP-ENC:arrayType” wsdl:arrayType=&quot;xsd:string[]&quot;/> </xs:restriction> </xs:complexContent> </xs:complexType> </li></ul><ul><li>Arrays are encoded in SOAP messages follows: <inputStringArray SOAP-ENC:arrayType=&quot;xsd:string[2]&quot;> <item xsi:type=“xsd:string”>hello</item> <item xsi:type=“xsd:string”>world!</item> </inputStringArray> </li></ul>
  36. 36. SOAP RPC Encoding (cont’d) <ul><li>Struct are just xs:complexTypes with xs:sequence (or xs:all): <xs:complexType name=”lightSwitch&quot;> <xs:sequence> <xs:element name=“light” type=“tns:switch”/> <xs:element name=“level” type=“xs:int”/> <xs:element name=“image” type=“xs:base64Binary”/> </xs:sequence> </xs:complexType> </li></ul>
  37. 37. RPC versus Doc/lit in WSDL <ul><li>Document/literal SOAP messages don’t include encodingStyle and XML types for request/responses are not constraint by the SOAP RPC encoding rules </li></ul><ul><li>Document style and literal use are declared in the bindings: <binding type=&quot;glossaryTerms&quot; name=&quot;b1&quot;> <soap:binding style=&quot;document” transport=&quot;http://schemas.xmlsoap.org/soap/http&quot;/> <operation> <soap:operation soapAction=&quot;http://example.com/getTerm&quot;/> <input> <soap:body use=&quot;literal&quot; /> </input> <output> <soap:body use=&quot;literal&quot; /> </output> </operation> </binding> </li></ul>
  38. 38. RPC versus Doc/lit in WSDL (cont’d) <ul><li>The parts in messages now refer to elements, which will be the request/response elements in the SOAP Body <definitions xmlns:m=“urn:examples:tempservice” …> <message name=&quot;getTermRequest&quot;> <part name=&quot;term&quot; element=”m:getTemp&quot;/> </message> <message name=&quot;getTermResponse&quot;> <part name=&quot;value&quot; element=”m:getTempResult&quot;/> </message> <portType name=&quot;glossaryTerms&quot;> <operation name=&quot;getTerm&quot;> <input message=&quot;getTermRequest&quot;/> <output message=&quot;getTermResponse&quot;/> </operation> </portType> </li></ul>
  39. 39. RPC versus Doc/lit in WSDL (cont’d) <ul><li>The parts in messages refer to elements that define the request and response elements in the SOAP Body of a message: <types> <xs:schema xmlns:xs=“http://www.w3.org/2001/XMLSchema” targetNamespace=“urn:examples:tempservice” … elementFormDefault=“qualified” attributeFormDefault=“unqualified”> <xs:element name=“getTemp”> <xs:complexType> <xs:sequence> <xs:element name=“zipCode” type=“xs:string”/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name=“getTempResult”> <xs:complexType> <xs:sequence> <xs:element name=“temp” type=“xs:float”/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </types> </li></ul>
  40. 40. SOAP Request Message in Doc/Lit Style <ul><li>Note the absence of SOAP-ENC:encodingStyle and xsi:type in the message: <?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance’ xmlns:xsd='http://www.w3.org/2001/XMLSchema’ xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body> <n:getTemp xmlns:n='urn:examples:tempservice'> <n:zipCode>32306</n:zipCode> </n:getTemp> </soap:Body> </soap:Envelope> </li></ul>
  41. 41. SOAP Multi-ref Encoding <ul><li>SOAP operation (request/response) </li></ul><ul><li>The XSD type system to represent values of primitive types in XML, such as bool, integer, float, string, base64 </li></ul><ul><li>A SOAP array type to encode sparse and partial arrays </li></ul><ul><li>Id-href XML attributes to implement graph edges to encode multi-ref objects </li></ul><env:Envelope> <env:Body env:encodingStyle=“…”> <ns:myRemoteOp> <arg1 xsi:type=“xsd:int”>123</arg1> <arg2 enc:arrayType=“xsd:string[5]”> <item>abc</item> <item href=“#_1”/> <item href=“#_1”/> <item href=“#_2”/> <item enc:position=“[5]”>xyz</item> </arg2> </ns:myRemoteOp> <mref id=“_1”>abc</mref> <mref id=“_2”>def</mref> </env:Body> </env:Envelope>
  42. 42. Static Structure Analysis for SOAP RPC Encoding <x> <x href =“#456”/> … <x href =“#456”/> … </x> … <mref id =“456”>…</mref> <x> <y href =“#123”/> … <y href =“#123”/> … </x> … <mref id =“123”>…</mref> <x> <y>…</y> <z>…</z> … </x> Example XML Instance <complexType name=“X”> <sequence>…</sequence> </complexType <complexType name=“X”> <sequence>…</sequence> </complexType> <complexType name=“Y”> <sequence>…</sequence> </complexType <complexType name=“X”> <sequence> <element name=“y” type=“tns:Y”/> <element name=“z” type=“tns:Z”/> </sequence> … </complexType> XML Schema Structure X Y Z X Y X X X X
  43. 43. gSOAP Constructs a Plausible Object Model for Serialization typedef int SSN; struct Node { int val; int *ptr; float num; struct Node *next; }; val ptr num next Node SSN Data model graph (arcs denote all possible pointer references) Source code type definitions
  44. 44. Generating an XML Schema Definition for Serialized XML val ptr num next Node SSN <simpleType name=“SSN”> <restriction base=“int”/> </simpleType> <complexType name=“Node”> <sequence> <element name=“val” type=“int”/> <element name=“ptr” type=“int” minOccurs=“0”/> <element name=“num” type=“float”/> <element name=“next” type=“tns:Node” minOccurs=“0”/> </sequence> </complexType> Data model graph
  45. 45. Generating Code for Runtime Points-To Analysis serialize_pointerToint(int *p) { if (p != NULL) { // lookup and mark (p,TYPE_int) // as target in ptr hash table } } serialize_Node(struct Node *p) { if (p != NULL) { // lookup and mark (p,TYPE_Node) // as target in ptr hash table mark_embedded(&p->val,TYPE_int); serialize_pointerToint(p->ptr); // skip p->num serialize_pointerToNode(p->next); } } val ptr num next Node SSN Data model graph
  46. 46. Generating Serialization Code put_pointerToint(int *p) { if (p != NULL) { // lookup (p,TYPE_int) // if embedded , then output “ref” // if single , then output value // if multi , then output value // with “id” and mark embedded } } put_Node(struct Node *p) { if (p != NULL) { // lookup (p,TYPE_Node) // if embedded , then output “ref” // if single , then output value // if multi , then output value // with “id” and mark embedded put_int(&p->val); put_pointerToint(p->ptr); put_float(&p->num) put_pointerToNode(p->next); } } val ptr num next Node SSN
  47. 47. Serialization Example val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B Ptr hash table after runtime points-to analysis by the generated algorithm constructed from the data model single 1 4 int C 4 single 1 16 Node B 3 embedded 1 4 int B 2 multi 2 16 Node A 1 RefType PtrCount PtrSize PtrType PtrLoc ID
  48. 48. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B embedded, id=2 multi, id=1 single single multi, id=1
  49. 49. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  50. 50. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  51. 51. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  52. 52. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  53. 53. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> </next> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  54. 54. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> </next> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  55. 55. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> </next> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  56. 56. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> <num>2.3</num> </next> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  57. 57. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> <num>2.3</num> <next ref=“#_1”/> </next> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  58. 58. Serialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node loc=A SSN loc=C val =456 ptr =C num =2.3 next =A Node loc=B <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> <num>2.3</num> <next ref=“#_1”/> </next> </Node> embedded, id=2 multi, id=1 single single multi, id=1
  59. 59. Deserialization Example <Node id=“_1”> </Node> val =? ptr =? num =? next =? Node id=1 Recursive descent parsing with object deserialization operations as semantic actions
  60. 60. Deserialization Example (cont’d) val =123 ptr =? num =? next =? Node <Node id=“_1”> <val>123</val> </Node> id=1 Recursive descent parsing with object deserialization operations as semantic actions
  61. 61. Deserialization Example (cont’d) val =123 ptr =? num =? next =? Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> </Node> id=1 ref=2 (unresolved) Recursive descent parsing with object deserialization operations as semantic actions
  62. 62. Deserialization Example (cont’d) val =123 ptr =? num =1.4 next =? Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> </Node> id=1 ref=2 (unresolved) Recursive descent parsing with object deserialization operations as semantic actions
  63. 63. Deserialization Example (cont’d) val =123 ptr =? num =1.4 next =B Node val =? ptr =? num =? next =? Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> </next> </Node> id=1 ref=2 (unresolved) Recursive descent parsing with object deserialization operations as semantic actions
  64. 64. Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B Node val =456 ptr =? num =? next =? Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> </next> </Node> id=1 id=2 Recursive descent parsing with object deserialization operations as semantic actions
  65. 65. Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node val =456 ptr =C num =? next =? Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> </next> </Node> id=1 id=2 Recursive descent parsing with object deserialization operations as semantic actions
  66. 66. Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node SSN val =456 ptr =C num =2.3 next =? Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> <num>2.3</num> </next> </Node> id=1 id=2 Recursive descent parsing with object deserialization operations as semantic actions
  67. 67. Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node SSN val =456 ptr =C num =2.3 next =A Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> <num>2.3</num> <next ref=“#_1”/> </next> </Node> id=1 Recursive descent parsing with object deserialization operations as semantic actions
  68. 68. Deserialization Example (cont’d) val =123 ptr =B num =1.4 next =B =789 Node SSN val =456 ptr =C num =2.3 next =A Node <Node id=“_1”> <val>123</val> <ptr ref=“#_2”/> <num>1.4</num> <next> <val id=“_2”>456</val> <ptr>789</ptr> <num>2.3</num> <next ref=“#_1”/> </next> </Node> id=1 Recursive descent parsing with object deserialization operations as semantic actions
  69. 69. Converting a WSDL to Code with gSOAP <ul><li>The wsdl2h tool converts a (set of) WSDL files and schemas to a header file </li></ul><ul><li>The header file is then processed by soapcpp2 as before </li></ul>
  70. 70. WS-* Protocols and Plugins
  71. 71. SOAP With MTOM Attachments <ul><li>Raw binary data can be transported in a SOAP message as base64 </li></ul><ul><li>MTOM ( Message Transmission Optimization Mechanism ) using MIME attachments to carry binary data with a SOAP message </li></ul><ul><ul><li>Supports embedding of type and other information </li></ul></ul><ul><ul><li>Allows streaming (attachments produced on demand) </li></ul></ul><ul><ul><li>Example HTTP header for SOAP with MTOM: POST / HTTP/1.1 Host: www.example.com Content-Type: multipart/related; boundary=”mimeboundary&quot;; type=&quot;application/xop+xml&quot;; start=&quot;<soapmsg>&quot;; start-info=&quot;application/soap+xml; charset=utf-8&quot; </li></ul></ul>
  72. 72. SOAP With MTOM Attachments (cont’d) <ul><li>Example HTTP body with SOAP message and MTOM attachment: --mimeboundary Content-Type: application/xop+xml;charset=utf-8;type=application/soap+xml Content-Transfer-Encoding: binary Content-ID: <soapmsg> <SOAP-ENV:Envelope xmlns:SOAP-ENV=”…” xmlns:xop=&quot;http://www.w3.org/2004/08/xop/include&quot; xmlns:xmlmime=&quot;http://www.w3.org/2004/11/xmlmime&quot; <SOAP-ENV:Body> <m:PutImage xmlns:m=&quot;http://www.example.com/test.wsdl&quot;> <m:data xmlmime:contentType=” image/jpeg &quot;> <xop:Include href=&quot; cid:image &quot;/> </m:data> </m:PutImage> </SOAP-ENV:Body> </SOAP-ENV:Envelope> --mimeboundary Content-Type: image/jpeg Content-Transfer-Encoding: binary Content-ID: < image > … image data … --mimeboundary-- </li></ul>
  73. 73. WS-Addressing <ul><li>WS-Addressing is a Web services protocol for routing messages (request, response, and faults) </li></ul><ul><li>Supports message transmission through networks with processing nodes such as endpoint managers, firewalls, and gateways <S:Envelope xmlns:S=&quot;http://www.w3.org/2003/05/soap-envelope&quot; xmlns:wsa=&quot;http://schemas.xmlsoap.org/ws/2004/08/addressing&quot;> <S:Header> <wsa:MessageID> uuid:6B29FC40-CA47-1067-B31D-00DD010662DA </wsa:MessageID> <wsa:ReplyTo> <wsa:Address>http://business456.example/client1</wsa:Address> </wsa:ReplyTo> <wsa:To>http://fabrikam123.example/Purchasing</wsa:To> <wsa:Action>http://fabrikam123.example/SubmitPO</wsa:Action> </S:Header> <S:Body> ... </S:Body> </S:Envelope> </li></ul>
  74. 74. WS-Addressing (cont’d) <ul><li>WS-Addressing header elements within the SOAP Header: </li></ul><ul><ul><li><wsa:MessageID> xs:anyURI </wsa:MessageID> defines a unique message ID, e.g. UUID (optional) </li></ul></ul><ul><ul><li><wsa:RelatesTo RelationshipType=&quot;...&quot;?> xs:anyURI </wsa:RelatesTo> conveys the message ID of the related message, e.g. the request message ID when this is a reply message (required for responses) </li></ul></ul><ul><ul><li><wsa:To> xs:anyURI </wsa:To> the destination address (required) </li></ul></ul><ul><ul><li><wsa:Action> xs:anyURI </wsa:Action> conveys the SOAP action property (required) </li></ul></ul><ul><ul><li><wsa:From> endpoint-reference </wsa:From> the source endpoint information (optional) </li></ul></ul><ul><ul><li><wsa:ReplyTo> endpoint-reference </wsa:ReplyTo> the reply endpoint (required for request with an expected reply) </li></ul></ul><ul><ul><li><wsa:FaultTo> endpoint-reference </wsa:FaultTo> the fault endpoint (optional) </li></ul></ul>
  75. 75. WS-Security <ul><li>WS-Security provides message-level security </li></ul><ul><ul><li>HTTPS provides end-to-end transport-level security </li></ul></ul><ul><li>Authentication </li></ul><ul><ul><li>Username and (digest) password (with nonce, timestamps) </li></ul></ul><ul><li>Digital signatures </li></ul><ul><ul><li>XML DSig with DSA, HMAC, … </li></ul></ul><ul><ul><li>Can sign all or specific parts of the message </li></ul></ul><ul><ul><li>Embedding of security tokens such as certificates </li></ul></ul><ul><ul><li>Support for SAML </li></ul></ul><ul><li>Encryption </li></ul><ul><ul><li>XML Enc with RSA, … </li></ul></ul>
  76. 76. Username Token <ul><li>The Username token security header in wsse:Security contains a username and password in plain text or a digest password: <SOAP-ENV:Envelope xmlns:SOAP-ENV=“…” xmlns:wsse=“…” xmlns:wsu=“…”> <SOAP-ENV:Header> <wsse:Security SOAP-ENV:mustUnderstand=&quot;1&quot;> <wsse:UsernameToken wsu:Id=&quot;User&quot;> <wsse:Username>engelen</wsse:Username> <wsse:Password Type=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest&quot;>/u5faawcfIeve1yHCsdXAWyIlbU=</wsse:Password> <wsse:Nonce>NDU0MGE5YjljYTUzYzAzZjA2MTc=</wsse:Nonce> <wsu:Created>2006-10-26T12:27:37Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </SOAP-ENV:Header> <SOAP-ENV:Body> … </SOAP-ENV:Body> </SOAP-ENV:Envelope> </li></ul>
  77. 77. Security Timestamps <ul><li>A timestamp can be included to define the lifetime of a message </li></ul><ul><li>The timestamp will only be tamper proof when digitally signed, hence the wsu:Id which is referenced by the signature info <SOAP-ENV:Envelope …> <SOAP-ENV:Header> <wsse:Security> <wsu:Timestamp wsu:Id=&quot;timestamp&quot;> <wsu:Created>2001-09-13T08:42:00Z</wsu:Created> <wsu:Expires>2001-10-13T09:00:00Z</wsu:Expires> </wsu:Timestamp> ... </wsse:Security> ... </SOAP-ENV:Header> <SOAP-ENV:Body> ... </SOAP-ENV:Body> </SOAP-ENV:Envelope> </li></ul>
  78. 78. Signatures <ul><li>The wsse:BinarySecurityToken contains the public key </li></ul><ul><li>The ds:Signature element contains signature info with digest value for each signed message part and the signature value <wsse:Security> <wsse:BinarySecurityToken wsu:Id=“X509Token” …> public key </wsse:BinarySecurityToken> <ds:Signature> <ds:SignedInfo> what is signed: reference URI to signed part with digest of that XML message part how it is signed: digests algorithms and canonicalization of XML </ds:SignedInfo> <ds:SignatureValue> signature </ds:SignatureValue> <ds:KeyInfo> <wsse:SecurityTokenReference> <wsse:Reference URI=&quot;#X509Token&quot;/> </wsse:SecurityTokenReference> </ds:KeyInfo> </ds:Signature> </wsse:Security> </li></ul>
  79. 79. Signature Example <wsse:Security> <wsse:BinarySecurityToken …> … </wsse:BinarySecurityToken> <ds:Signature> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;/> <ds:SignatureMethod Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#rsa-sha1&quot;/> <ds:Reference URI=&quot;#myBody&quot;> <ds:Transforms> <ds:Transform Algorithm=&quot;http://www.w3.org/2001/10/xml-exc-c14n#&quot;/> </ds:Transforms> <ds:DigestMethod Algorithm=&quot;http://www.w3.org/2000/09/xmldsig#sha1&quot;/> <ds:DigestValue>EULddytSo1...</ds:DigestValue> </ds:Reference> </ds:SignedInfo> <ds:SignatureValue>BL8jdfToEb1l/vXcMZNNjPOV...</ds:SignatureValue> <ds:KeyInfo> <wsse:SecurityTokenReference> <wsse:Reference URI=&quot;#X509Token&quot;/> </wsse:SecurityTokenReference> </ds:KeyInfo> </ds:Signature> </wsse:Security>
  80. 80. List of WS-* Protocols <ul><li>Messaging </li></ul><ul><ul><li>SOAP </li></ul></ul><ul><ul><li>SOAP with Attachments (SwA) </li></ul></ul><ul><ul><li>SOAP with MTOM (Message Transmission Optimization Mechanism) </li></ul></ul><ul><ul><li>XML-RPC : a simpler XML RPC format (no WSDL or schemas) </li></ul></ul><ul><ul><li>WS-Addressing : routing, endpoints, and addressing properties </li></ul></ul><ul><li>Service description </li></ul><ul><ul><li>WSDL </li></ul></ul><ul><ul><li>WS-MetadataExchange : how an endpoint can request the various types of metadata it may need to effectively communicate with the service </li></ul></ul><ul><ul><li>WS-Policy : describes the capabilities, requirements, and general characteristics of a service </li></ul></ul>
  81. 81. List of WS-* Protocols <ul><li>Directory access and discovery </li></ul><ul><ul><li>UDDI (Universal Description, Discovery, and Integration) v2/v3 </li></ul></ul><ul><ul><li>WS-Discovery : a multicast discovery protocol to locate services on a network </li></ul></ul><ul><li>Managing services </li></ul><ul><ul><li>WS-Management : for management of servers, devices, applications </li></ul></ul><ul><li>Transaction-based services </li></ul><ul><ul><li>WS-Transaction : describes the coordination types atomic transaction (TA) and business activity (BA) </li></ul></ul><ul><li>Publish/subscribe </li></ul><ul><ul><li>WS-Eventing </li></ul></ul><ul><ul><li>WS-Notification </li></ul></ul><ul><li>Security and reliability </li></ul><ul><ul><li>HTTPS (transport-level) </li></ul></ul><ul><ul><li>WS-Security (message-level) </li></ul></ul><ul><ul><li>WS-ReliableMessaging </li></ul></ul>
  82. 82. Other Notable WS-* Protocols <ul><li>Managing resources: Web Services Resource Framework (WSRF) </li></ul><ul><ul><li>WS-ResourceProperties : defines are resource’s properties </li></ul></ul><ul><ul><li>WS-ResourceLifetime : inspect and monitor the lifetime of a resource </li></ul></ul><ul><ul><li>WS-ServiceGroup : defines how resources are grouped together for a domain specific purpose (service classification and constraints) </li></ul></ul><ul><ul><li>WS-BaseFaults : defines faults related to resource management </li></ul></ul><ul><li>Managing resources </li></ul><ul><ul><li>WS-Transfer : operations for sending and receiving the representation of a given resource and operations for creating and deleting a resource </li></ul></ul><ul><li>Best practices </li></ul><ul><ul><li>Provide additional information to improve interoperability between vendor implementations </li></ul></ul><ul><ul><li>WS-I Basic profile (BP1.0a, BP1.1) </li></ul></ul><ul><ul><li>WS-I Basic security profile </li></ul></ul>
  83. 83. Other Notable WS-* Protocols <ul><li>Device Profile for Web Services (DPWS) </li></ul><ul><ul><li>Goals similar to universal plug and play (UPnP) </li></ul></ul><ul><ul><li>Seamless integration and discovery of devices over the Internet </li></ul></ul><ul><ul><ul><li>Printing, scanning, etc. over Internet by discovering these services </li></ul></ul></ul><ul><ul><ul><li>Uploading images from camera to PC over the (wireless) Internet </li></ul></ul></ul><ul><ul><li>Microsoft Vista natively integrates DPWS </li></ul></ul><ul><li>Builds on </li></ul><ul><ul><li>WS-Eventing (publish/subscribe) </li></ul></ul><ul><ul><li>WS-Discovery </li></ul></ul><ul><ul><li>WS-Addressing </li></ul></ul><ul><ul><li>WS-Security </li></ul></ul><ul><ul><li>WS-Policy </li></ul></ul><ul><ul><li>WS-MetaExchange </li></ul></ul>
  84. 84. To be continued…
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×