DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Managing Data Residency, the Demo
  • What Is React? A Complete Guide
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Introduction To Git

Trending

  • Managing Data Residency, the Demo
  • What Is React? A Complete Guide
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Introduction To Git
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Secure, Scalable and Dynamic Invocation of SOAP in Python with Zato and Suds

Secure, Scalable and Dynamic Invocation of SOAP in Python with Zato and Suds

Dariusz Suchojad user avatar by
Dariusz Suchojad
·
Feb. 19, 14 · Interview
Like (1)
Save
Tweet
Share
3.07K Views

Join the DZone community and get the full member experience.

Join For Free

Zato ESB and app server in Python has grown additional means through which it is now even easier to invoke SOAP services without a need for generating stub classes or clients.

Given an existing WSDL, all that is needed is filling out a couple of forms and a pool of SOAP clients is automatically generated and available in a cluster

Built on top of Suds, the feature is available in git master and here's a preview showing how to consume SOAP services without any need for direct XML manipulations in order to build a RESTful service validating credit card numbers with JSON output.

First, let's upload the service that will connect to SOAP and produce JSON on output.

Note that the service doesn't really know what type of output it produces - this is configured from the GUI and no code changes are needed for the service to produce XML instead of JSON.

   # -*- coding: utf-8 -*-
   
   # Zato
   from zato.server.service import Service
   
   class ValidateCreditCard(Service):
   
       class SimpleIO:
           input_required = ('number',)
           output_required = ('card_type', 'is_valid')
   
       def handle(self):
           conn = self.outgoing.soap['Credit Card Validator'].conn
   
           with conn.client() as client:
   
               # Invoke SOAP dynamically - no need for stub classes
               result = client.service.CheckCC(self.request.input.number)
   
               # Results are turned into Python objects automatically
               self.response.payload.card_type = result.CardType
               self.response.payload.is_valid = result.CardValid

While not strictly required, let's say we need to secure our REST service with Basic Auth: Form to create an HTTP Basic Auth definition

Now a channel is created through which requests will flow in. Note that the URL path is a pattern - all named attributes, such as *number* here, are available as input to services.

And although it's not used in this example, both JSON or XML can be mixed on input with URL parameters with full control of what has priority over other parts. Form to create a new HTTP channel

Next an outgoing SOAP connection is needed. Note that its serialization type is Suds - this is the new feature. The WSDL points to a free SOAP service online courtesy of CDYNE .

In the example below, each server will be given a pool of 20 SOAP clients, each generated dynamically on fly from the WSDL provided on input.

If you're coming from Java or C# background you'll note that no stubs nor client classes need to be generated. This is all taken care of behind the scenes so one can focus on invoking SOAP services straightaway. Form to create a new outgoing SOAP connection

With all that in place, the Zato service can now be invoked. curl is used from command line in the examples below:

   $ curl -u user:password localhost:17010/validate-cc/4111111111111111
   {"response": {"card_type": "VISA", "is_valid": true}}
   $
   $ curl -u user:password localhost:17010/validate-cc/123456789
   {"response": {"card_type": "NONE", "is_valid": false}}
   $

What if the WSDL changes with time? You only need to click 'Reload WSDL' and a new pool of SOAP clients will be created using the newest contents. Arrow points to a link through which WSDL can be reloaded

The feature will be released in the upcoming 1.2 release and until then - please use git master version.

SOAP Web Protocols Python (language)

Opinions expressed by DZone contributors are their own.

Trending

  • Managing Data Residency, the Demo
  • What Is React? A Complete Guide
  • Why You Should Consider Using React Router V6: An Overview of Changes
  • Introduction To Git

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: