"Calculator" Example - "Add" Operation

This section provides a tutorial example on how to use the 'Add' operation of the free Web service 'Calculator' provided by dneonline.com.

Here is what I did to test the "Calculator" Web service with the Zeep Python library.

1. Write the following Python test script with logging turned on at the DEBUG level.

#- Calculator-Test.py
#- Copyright (c) 2024 HerongYang.com. All Rights Reserved.
#
import sys
from zeep import Client
import logging.config

logging.config.dictConfig({
    'version': 1,
    'formatters': {
        'verbose': {
            'format': '%(name)s: %(message)s'
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'zeep.transports': {
            'level': 'DEBUG',
            'propagate': True,
            'handlers': ['console'],
        },
    }
})

wsdl = "http://www.dneonline.com/calculator.asmx?WSDL"

op = sys.argv[1]
p1 = sys.argv[2]
p2 = sys.argv[3]

client = Client(wsdl)

res = client.service[op](p1, p2)
print("\nTest result:")
print('   {1} {0} {2} = {3}'.format(op, p1, p2, res))

2. Run the test script to try the "Add" operation:

herong$ python3 Calculator-Test.py Add 9 2 

zeep.transports: Loading remote data from: 
  http://www.dneonline.com/calculator.asmx?WSDL

zeep.transports: HTTP Post to 
  http://www.dneonline.com/calculator.asmx:

<?xml version="1.0" encoding="utf-8"?>
<soap-env:Envelope 
  xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:Add xmlns:ns0="http://tempuri.org/">
      <ns0:intA>9</ns0:intA>
      <ns0:intB>2</ns0:intB>
    </ns0:Add>
  </soap-env:Body>
</soap-env:Envelope>

zeep.transports: HTTP Response from 
  http://www.dneonline.com/calculator.asmx (status: 200):

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddResponse xmlns="http://tempuri.org/">
      <AddResult>11</AddResult>
    </AddResponse>
  </soap:Body>
</soap:Envelope>

Test result:
   9 Add 2 = 11

It works! You can continue to run more tests on "Add", "Subtract", "Multiple" or "Divide" operation.

If you want to invoke the Web service without , you can take the SOAP request from the debugging output and POST it directly to the server at http://www.dneonline.com/calculator.asmx.

Table of Contents

 About This Book

 Python SOAP Client: Zeep

 SoapUI - Web Service Testing Tool

 SOAP Web Service and SoapUI

 REST Web Service and SoapUI

 Mock Web Services - herongyang.com/Service

 "SoapResponder" and Web Service Test Tool

"Calculator" for 4 Integer Operations

 "Calculator" - WSDL and Operations

"Calculator" Example - "Add" Operation

 DataFlex Web Service for Country Information

 LatLonListCityNames - Return Latitudes and Longitudes of US Cities

 LatLonListZipCode - Return Latitudes and Longitudes of US Zip Code

 TempConvert Web Service for Temperature Conversion

 NDFDgenByDay - US Weather Forecast by Day

 NDFDgen - US-Weather Forecast for a Single Location

 Currency Exchange Rate

 Bitcoin Blockchain Data API (or Explorer)

 flickr.interestingness.getList - Get Interesting Photos

 UUID/GUID Generator

 NumberToWords - Convert Number in Digits to Words

 TitleCaseWordsWithToken - Words to Title Case Format

 "PUG SOAP" Web Service for PubChem Database

 RSC - ChemSpider APIs

 Discontinued: Currency Converter by kowabunga.net

 Discontinued: GetCountries - Get All Countries and Territories

 Discontinued: GetCurrencies - Get Currencies from All Countries

 Discontinued: GetGMTbyCountry - Get GMT Information of a Given Country

 Discontinued: GetISD - Get ISD Phone Code of a Given Country

 Discontinued: GetCitiesByCountry - Get Cities by Country

 Discontinued: GetInfoByState - Get ZIP Codes of a Given US State

 Discontinued: GetAirportInformationByCountry - Get Airport Code by Country

 Discontinued: GetGeoIP - Get Country by IP Address

 Discontinued: ConvertTemp - Convert Temperature Unit

 Discontinued: ChangeLengthUnit - Convert Length Unit

 Discontinued: ConvertWeight - Convert Weight Unit

 Discontinued: ChangeAreaUnit - Convert Area Unit

 Discontinued: Code39 - Generate Bar Code Images in Code 39 Format

 Discontinued: GenerateBarCode - Generate Bar Code Images

 Discontinued: GetMortgagePayment - Calculate Mortgage Payment

 Discontinued: ConversionRate - Get Currency Exchange Rate

 Discontinued: GetQuote - Get Stock Quote

 Discontinued: GetSunSetRiseTime - Get Sunrise and Sunset Time

 Discontinued: GetWeatherByZipCode - Get Weather by ZIP Code in US

 Discontinued: getTime - Get the Current Time

 Discontinued: questionSearch - Search Yahoo! Questions and Answers

 Discontinued: Hotwire - Get Travel Ticker Deals

 Archived Tutorials

 References

 Full Version in PDF/EPUB