skip to main content

Web Service option : COBOL approach using SOAP : COBOL SOAP consumer

COBOL SOAP consumer
In order to develop a COBOL SOAP consumer (client-side), to invoke SOAP Web Service, the COBOL program should take advantage of HTTPClient class. That class contains several useful methods to work with SOAP Web Service.
In the isCOBOL sample folder you find the folder eis/webservices/soap/client that contains an example of COBOL client program called "IP2GEO.cbl" that shows how to use a SOAP Web Service available over internet at http://ws.cdyne.com/ip2geo/ip2geo.asmx .
This service "Resolves IP addresses to Organization, Country, City, and State/Province, Latitude, Longitude. In most US cities it will also provide some extra information such as Area Code, and more."
A SOAP Web Service usually provides a way to inquire the functionality available and the parameters that should be used. To simplify the working storage definition able to manage the XML envelope, a the STREAM2WRK utility can be used.
That utility is able to read WSDL definition obtained adding ?WSDL to the Web Service URL definition, something like: http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL generates the following working storage:
      *> binding name=ResolveIP, style=document
       01  soap-in-ResolveIP identified by 'soapenv:Envelope'.
           03 identified by 'xmlns:soapenv' is attribute.
            05 filler pic x(39value 'http://www.w3.org/2003/05/soap-envelope'.
           03 identified by 'xmlns:tns' is attribute.
            05 filler pic x(20value 'http://ws.cdyne.com/'.
           03 identified by 'soapenv:Body'.
               06 identified by 'tns:ResolveIP'.
                07 identified by 'tns:ipAddress'.
                 08 a-ipAddress pic x any length.
                07 identified by 'tns:licenseKey'.
                 08 a-licenseKey pic x any length.
       01  soap-out-ResolveIP identified by 'Envelope'
                 namespace 'http://www.w3.org/2003/05/soap-envelope'.
           03 identified by 'Body'.
               06 identified by 'ResolveIPResponse'
                07 identified by 'ResolveIPResult'.
                 08 identified by 'City'.
                  09 a-City pic x any length.
                 08 identified by 'StateProvince'.
                  09 a-StateProvince pic x any length.
                 08 identified by 'Country'.
                  09 a-Country pic x any length.
                 08 identified by 'Organization'.
                  09 a-Organization pic x any length.
                 08 identified by 'Latitude'.
                  09 a-Latitude pic s9(16)v9(2).
                 08 identified by 'Longitude'.
                  09 a-Longitude pic s9(16)v9(2).
                 08 identified by 'AreaCode'.
                  09 a-AreaCode pic x any length.
                 08 identified by 'TimeZone'.
                  09 a-TimeZone pic x any length.
                 08 identified by 'HasDaylightSavings'.
                  09 a-HasDaylightSavings pic x any length.
                 08 identified by 'Certainty'.
                  09 a-Certainty pic s9(5).
                 08 identified by 'RegionName'.
                  09 a-RegionName pic x any length.
                 08 identified by 'CountryCode'.
                  09 a-CountryCode pic x any length.
This program has the objective to invoke the ResolveIP functionality providing the IP address and receiving some geographic information like City, State, Country, etc.
This program must take the following steps:
           class http-client as "com.iscobol.rts.HTTPClient"
       copy "ip2geo.cpy".
           move "209.235.175.10"   to a-ipAddress
                           "http://ws.cdyne.com/ip2geo/ip2geo.asmx"
Note - The type "text/xml;charset=utf-8" is suitable for SOAP v1.1. If the service is SOAP v1.2, use "application/soap+xml; charset=utf-8" instead.
           http:>getResponseCode (response-code).
           display "Response code: " response-code.
           if response-code = 200
              http:>getResponseXML (soap-ResolveIP-output)
              display "City=" a-city
              display "StateProvince=" a-stateProvince
              display "Country=" a-country
              display "Organization=" a-Organization
              display "Latitude=" a-latitude
              display "Longitude=" a-longitude
              display "AreaCode=" a-areaCode
              display "TimeZone=" a-timeZone
              display "Daylight savings=" a-HasDaylightSavings
              display "Certainty=" a-certainty
              display "RegionName=" a-regionName
              display "CountryCode=" a-countryCode
Compile the program with the command:
and run it with the command:
This is the result of execution of IP2GEO that consumes the ResolveIP SOAP Web Service:
 

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left