SlideShare a Scribd company logo
SOA WITH C, C++, PHP …
  Supun Kamburugamuva
  supun@wso2.com
SOA Workshop
                                        Santa Clara


Language of your choice
   You must have Freedom to choose
   You must have Reasons to choose
SOA Workshop
                                                   Santa Clara


Why C?
   Most portable
   Less memory
   Faster
   Many interesting applications written in C
     HTTPD

     Ruby

     MySQL

     PHP
SOA Workshop
                                                      Santa Clara


Why C++?
   Widely used (and some legacy)
     Financial,   Banking, Telco, DBMS, Embedded
   Performance, Flexibility, Control
SOA Workshop
                                                  Santa Clara


Why PHP?
   Installed on over 20 million websites
   1 million web servers
   Easiest way to write services and clients
SOA Workshop
                                 Santa Clara


SOA in a Heterogeneous World
SOA Workshop
                           Santa Clara


Expectations
   Tooling for WSDL
   Security
   Interoperability
   Binary attachments
   Reliability
   Support
SOA Workshop
                                                                       Santa Clara


PHP Web Services Frameworks

    Package         Written in   WSDL      Security   Attachments Reliability


 PHP5 SOAP Ext          C        Partial     No           No           No


    NuSOAP            PHP         Yes        No           No           No


SCA with PHP(IBM)     PHP         Yes        No           No           No


 WSO2 WSF/PHP           C         Yes        Yes          Ye s        Ye s
SOA Workshop
                                                  Santa Clara




 Framework that improves PHP user’s ability to
  provide and consume Web services
 Capable of dealing with secure and reliable

  messaging even with binary data, the only PHP
  software package to offer those features
 The framework is inter-operable with non-PHP

  implementations, allowing it to be integrated with
  enterprise applications seamlessly
SOA Workshop
  Santa Clara
SOA Workshop
                                                                                            Santa Clara


     PHP Example – Secure Service
1.    function echoFunction($inMessage) {
2.         $returnMessage = new WSMessage($inMessage->str);
3.         return $returnMessage;
4.     }


1.     $pub_key = ws_get_cert_from_file("../keys/alice_cert.cert");
2.     $pvt_key = ws_get_key_from_file("../keys/bob_key.pem");


1.     $operations = array("echoString" => "echoFunction");


1.     $sec_array = array("encrypt" => TRUE, "algorithmSuite" => "Basic256Rsa15",
2.                          "securityTokenReference" => "IssuerSerial");


1.     $actions = array("http://php.axis2.org/samples/echoString" => "echoString");


1.     $policy = new WSPolicy(array("security"=>$sec_array));
2.     $sec_token = new WSSecurityToken(array("privateKey" => $pvt_key,
3.                                              "receiverCertificate" =>$pub_key));


1.     $service = new WSService(array("actions" => $actions,
2.                                "operations" => $operations,
3.                                "policy" => $policy, "securityToken" => $sec_token));


1.     $service->reply();
SOA Workshop
                                                                                 Santa Clara


     PHP Example – Secure Client
1.   $rec_cert = ws_get_cert_from_file("../keys/bob_cert.cert");
2.   $pvt_key = ws_get_key_from_file("../keys/alice_key.pem");

1.   $reqMessage = new WSMessage($reqPayloadString, array("to"=>
2.       "http://localhost/samples/security/encryption/encrypt_service.php",
3.       "action" => "http://php.axis2.org/samples/echoString"));

1.   $sec_array = array("encrypt"=>TRUE, "algorithmSuite" => "Basic256Rsa15",
2.                          "securityTokenReference" => "IssuerSerial");

1.   $policy = new WSPolicy(array("security"=>$sec_array));
2.   $sec_token = new WSSecurityToken(array("privateKey" => $pvt_key,
3.                                          "receiverCertificate" => $rec_cert));

1.   $client = new WSClient(array("useWSA" => TRUE, "policy" => $policy,
2.                                "securityToken" => $sec_token));

1.   $resMessage = $client->request($reqMessage);

1.   printf("Response = %s n", $resMessage->str);
SOA Workshop

How to adapt a C++ Application as Santa Clara




Web Services
SOA Workshop
                                                           Santa Clara


C/C++ Web Services Frameworks


   Package      WSDL      Security   Attachments   Reliability


 HydraExpress   Partial     No         Partial        No


   gSOAP         Yes      Partial       Yes           No


 WSO2 WSF/C     Partial     Ye s        Yes           Yes


WSO2 WSF/C++    Partial     Ye s        Yes           Yes
SOA Workshop
                                                      Santa Clara




   Designed for embedding within C or C++ software
    stacks to enable Web services
   All-in-one solution for the building and deploying of
    Web services
   Widest range of WS-* specifications
    implementations
   WS-Addressing, WS-Policy, WS-Security, WS-
    SecurityPolicy, WS-Reliable Messaging, MTOM and
    WS-eventing
SOA Workshop
                                                                                           Santa Clara


 C++ Example - Service
1.    #include <ServiceSkeleton.h>


1.    using namespace wso2wsf;


1.    class Echo: public ServiceSkeleton
2.    {
3.         public:
4.             WSF_EXTERN WSF_CALL Echo(){};


1.             OMElement* WSF_CALL invoke(OMElement *message, MessageContext *msgCtx);


1.             OMElement* WSF_CALL onFault(OMElement *message);


1.             void WSF_CALL init(){};
2.    };


1.    OMElement* Echo::invoke(OMElement *element, MessageContext *msgCtx)
2.    {
3.         OMElement *echoElement = new OMElement(element->getLocalname(),
4.             new OMNamespace(element->getNamespace(false)->getURI(),
5.                               element->getNamespace(false)->getPrefix()));
6.         OMElement *textElement = new OMElement("messsage");
7.         echoElement->addChild(textElement);
8.         textElement->setText("Hello World");
9.         return echoElement;
10.   }
SOA Workshop
                                                                                                     Santa Clara


     C++ Example - Client
1.    ServiceClient serviceClient(client_repo, end_point);


1.    OMNamespace * ns = new OMNamespace("http://ws.apache.org/rampart/c/samples",       "ns1");
2.    OMElement * payload = new OMElement(NULL, "echoIn", ns);
3.    OMElement * child = new OMElement(payload, "message", NULL);
4.    child->setText("Hello Service!");


1.    try
2.    {
3.          OMElement* response = serviceClient.request(payload,
4.                       "http://example.com/ws/2004/09/policy/Test/EchoRequest");
5.          if (response)
6.          {
7.                 cout << endl << "Response: " << response << endl;
8.          }
9.    }
10.   catch (AxisFault & e)
11.   {
12.         if (serviceClient.getLastSOAPFault())
13.         {
14.                cout << endl << "Fault: " << serviceClient.getLastSOAPFault() << endl;
15.         }
16.         else
17.         {
18.                   cout << endl << "Error: " << e << endl;
19.         }
20.   }
21.   delete payload;
SOA Workshop
                          Santa Clara


Web Services are Fast
SOA Workshop
                            Santa Clara


Web Services are Faster
SOA Workshop
                                                       Santa Clara


Web Services are Still Faster
   For secure services
     10K  messages C implementation x10 – x15 times
      faster than Java
     100k messages C implementation x6 – x8 times faster
      than Java
SOA Workshop
                                                                            Santa Clara


WSF/C++ Features
   SOAP 1.1 and SOAP 1.2
   WS-Addressing
       1.0
       Submission
   MTOM and SwA
       Support for caching large attachments
   WS-Security
       Base security standards mean that messages can be protected using
        Encryption, Authentication and Signature
       Including WS-SecureConversation and WS-Trust
   WSDL2CPP Code Generation tool
       Supports generating client stubs, service skeletons, build scripts and
        deployment scripts
SOA Workshop
                                                                                           Santa Clara


WSF/C++ Features
   WS-Policy and WS-Security Policy
       Enables using industry standard XML to confgure security

   SSL Enabled Transport Layer
   Reliable Messaging 1.0, 1.1 and WS-RMPolicy
       Enables reliability between platforms including message resending, duplicate detection and
        persistence

   Full REST support (GET, PUT, DELETE, POST)
    with custom URI Mapping
       Enables mapping a REST API easily and naturally
   Useful tools
       Tcpmon
       wsclient
SOA Workshop
                                                Santa Clara


References
   Various Web Services Frameworks
    http://wso2.org/projects/wsf
   Apache Axis2/C Web Services Performance
    http://wso2.org/library/3532
   Example applications for SOA
    http://incubator.apache.org/stonehenge/
   PHP Web Services Blog
    http://phpwebservices.blogspot.com/
SOA Workshop
               Santa Clara


Thank You!
   Q&A

More Related Content

WSO2 SOA with C and C++

  • 1. SOA WITH C, C++, PHP … Supun Kamburugamuva supun@wso2.com
  • 2. SOA Workshop Santa Clara Language of your choice  You must have Freedom to choose  You must have Reasons to choose
  • 3. SOA Workshop Santa Clara Why C?  Most portable  Less memory  Faster  Many interesting applications written in C  HTTPD  Ruby  MySQL  PHP
  • 4. SOA Workshop Santa Clara Why C++?  Widely used (and some legacy)  Financial, Banking, Telco, DBMS, Embedded  Performance, Flexibility, Control
  • 5. SOA Workshop Santa Clara Why PHP?  Installed on over 20 million websites  1 million web servers  Easiest way to write services and clients
  • 6. SOA Workshop Santa Clara SOA in a Heterogeneous World
  • 7. SOA Workshop Santa Clara Expectations  Tooling for WSDL  Security  Interoperability  Binary attachments  Reliability  Support
  • 8. SOA Workshop Santa Clara PHP Web Services Frameworks Package Written in WSDL Security Attachments Reliability PHP5 SOAP Ext C Partial No No No NuSOAP PHP Yes No No No SCA with PHP(IBM) PHP Yes No No No WSO2 WSF/PHP C Yes Yes Ye s Ye s
  • 9. SOA Workshop Santa Clara  Framework that improves PHP user’s ability to provide and consume Web services  Capable of dealing with secure and reliable messaging even with binary data, the only PHP software package to offer those features  The framework is inter-operable with non-PHP implementations, allowing it to be integrated with enterprise applications seamlessly
  • 10. SOA Workshop Santa Clara
  • 11. SOA Workshop Santa Clara PHP Example – Secure Service 1. function echoFunction($inMessage) { 2. $returnMessage = new WSMessage($inMessage->str); 3. return $returnMessage; 4. } 1. $pub_key = ws_get_cert_from_file("../keys/alice_cert.cert"); 2. $pvt_key = ws_get_key_from_file("../keys/bob_key.pem"); 1. $operations = array("echoString" => "echoFunction"); 1. $sec_array = array("encrypt" => TRUE, "algorithmSuite" => "Basic256Rsa15", 2. "securityTokenReference" => "IssuerSerial"); 1. $actions = array("http://php.axis2.org/samples/echoString" => "echoString"); 1. $policy = new WSPolicy(array("security"=>$sec_array)); 2. $sec_token = new WSSecurityToken(array("privateKey" => $pvt_key, 3. "receiverCertificate" =>$pub_key)); 1. $service = new WSService(array("actions" => $actions, 2. "operations" => $operations, 3. "policy" => $policy, "securityToken" => $sec_token)); 1. $service->reply();
  • 12. SOA Workshop Santa Clara PHP Example – Secure Client 1. $rec_cert = ws_get_cert_from_file("../keys/bob_cert.cert"); 2. $pvt_key = ws_get_key_from_file("../keys/alice_key.pem"); 1. $reqMessage = new WSMessage($reqPayloadString, array("to"=> 2. "http://localhost/samples/security/encryption/encrypt_service.php", 3. "action" => "http://php.axis2.org/samples/echoString")); 1. $sec_array = array("encrypt"=>TRUE, "algorithmSuite" => "Basic256Rsa15", 2. "securityTokenReference" => "IssuerSerial"); 1. $policy = new WSPolicy(array("security"=>$sec_array)); 2. $sec_token = new WSSecurityToken(array("privateKey" => $pvt_key, 3. "receiverCertificate" => $rec_cert)); 1. $client = new WSClient(array("useWSA" => TRUE, "policy" => $policy, 2. "securityToken" => $sec_token)); 1. $resMessage = $client->request($reqMessage); 1. printf("Response = %s n", $resMessage->str);
  • 13. SOA Workshop How to adapt a C++ Application as Santa Clara Web Services
  • 14. SOA Workshop Santa Clara C/C++ Web Services Frameworks Package WSDL Security Attachments Reliability HydraExpress Partial No Partial No gSOAP Yes Partial Yes No WSO2 WSF/C Partial Ye s Yes Yes WSO2 WSF/C++ Partial Ye s Yes Yes
  • 15. SOA Workshop Santa Clara  Designed for embedding within C or C++ software stacks to enable Web services  All-in-one solution for the building and deploying of Web services  Widest range of WS-* specifications implementations  WS-Addressing, WS-Policy, WS-Security, WS- SecurityPolicy, WS-Reliable Messaging, MTOM and WS-eventing
  • 16. SOA Workshop Santa Clara C++ Example - Service 1. #include <ServiceSkeleton.h> 1. using namespace wso2wsf; 1. class Echo: public ServiceSkeleton 2. { 3. public: 4. WSF_EXTERN WSF_CALL Echo(){}; 1. OMElement* WSF_CALL invoke(OMElement *message, MessageContext *msgCtx); 1. OMElement* WSF_CALL onFault(OMElement *message); 1. void WSF_CALL init(){}; 2. }; 1. OMElement* Echo::invoke(OMElement *element, MessageContext *msgCtx) 2. { 3. OMElement *echoElement = new OMElement(element->getLocalname(), 4. new OMNamespace(element->getNamespace(false)->getURI(), 5. element->getNamespace(false)->getPrefix())); 6. OMElement *textElement = new OMElement("messsage"); 7. echoElement->addChild(textElement); 8. textElement->setText("Hello World"); 9. return echoElement; 10. }
  • 17. SOA Workshop Santa Clara C++ Example - Client 1. ServiceClient serviceClient(client_repo, end_point); 1. OMNamespace * ns = new OMNamespace("http://ws.apache.org/rampart/c/samples", "ns1"); 2. OMElement * payload = new OMElement(NULL, "echoIn", ns); 3. OMElement * child = new OMElement(payload, "message", NULL); 4. child->setText("Hello Service!"); 1. try 2. { 3. OMElement* response = serviceClient.request(payload, 4. "http://example.com/ws/2004/09/policy/Test/EchoRequest"); 5. if (response) 6. { 7. cout << endl << "Response: " << response << endl; 8. } 9. } 10. catch (AxisFault & e) 11. { 12. if (serviceClient.getLastSOAPFault()) 13. { 14. cout << endl << "Fault: " << serviceClient.getLastSOAPFault() << endl; 15. } 16. else 17. { 18. cout << endl << "Error: " << e << endl; 19. } 20. } 21. delete payload;
  • 18. SOA Workshop Santa Clara Web Services are Fast
  • 19. SOA Workshop Santa Clara Web Services are Faster
  • 20. SOA Workshop Santa Clara Web Services are Still Faster  For secure services  10K messages C implementation x10 – x15 times faster than Java  100k messages C implementation x6 – x8 times faster than Java
  • 21. SOA Workshop Santa Clara WSF/C++ Features  SOAP 1.1 and SOAP 1.2  WS-Addressing  1.0  Submission  MTOM and SwA  Support for caching large attachments  WS-Security  Base security standards mean that messages can be protected using Encryption, Authentication and Signature  Including WS-SecureConversation and WS-Trust  WSDL2CPP Code Generation tool  Supports generating client stubs, service skeletons, build scripts and deployment scripts
  • 22. SOA Workshop Santa Clara WSF/C++ Features  WS-Policy and WS-Security Policy  Enables using industry standard XML to confgure security  SSL Enabled Transport Layer  Reliable Messaging 1.0, 1.1 and WS-RMPolicy  Enables reliability between platforms including message resending, duplicate detection and persistence  Full REST support (GET, PUT, DELETE, POST) with custom URI Mapping  Enables mapping a REST API easily and naturally  Useful tools  Tcpmon  wsclient
  • 23. SOA Workshop Santa Clara References  Various Web Services Frameworks http://wso2.org/projects/wsf  Apache Axis2/C Web Services Performance http://wso2.org/library/3532  Example applications for SOA http://incubator.apache.org/stonehenge/  PHP Web Services Blog http://phpwebservices.blogspot.com/
  • 24. SOA Workshop Santa Clara Thank You!  Q&A