SOAP request from Natural

I got a question about how to access a SOAP Web Service from Natural. I did not know, I never tried it. So I decided to try to access a Web Service on the Internet from Natural 6.1.1 on Windows XP.

First I looked for some services to call and I found the site: www.webservicex.net.

Then my problems really started how do I specify the proxy host to Natural? How to do a POST with DATA ALL.
With the help from Michael Muenster I learned that Natural on Windows get the proxy name and port from Windows. Natural UNIX and Natural 4.2 on mainframe use a Natural parameter.
I also found information in the Natural Documentation about the header Request-Method.

Now it works :smiley: I have enclosed an example:

define data local
1 #request              (a) dynamic
1 #response             (a) dynamic
1 #rc                   (i4)
*
1 #path                 (a) dynamic
1 #name                 (a) dynamic
1 #value                (a) dynamic
*
1 http-status-text      (a20)
*
1 #active_name          (a16)
1 #Reply
  2 Symbol              (a10)
  2 Last                (a10)
  2 Date                (a10)
  2 Time                (a7)
  2 Change              (a10)
  2 Open                (a10)
  2 High                (a10)
  2 Low                 (a10)
  2 Volume              (a10)
  2 MktCap              (a10)
  2 PreviousClose       (a10)
  2 PercentageChange    (a10)
  2 AnnRange            (a20)
  2 Earns               (a10)
  2 P-E                 (a10)
  2 Name                (a20)
end-define
*
input // 'Symbol:' Symbol //
   'Example: SOW.DE(Software AG), IBM, MSFT(Microsoft)'
*
compress
  '<?xml version="1.0" encoding="UTF-8" ?>' -
  '<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" ' -
  'xmlns:xmm="http://namespace.softwareag.com/entirex/xml/mapping" ' -
  'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' -
  'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' -
  'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">' -
  '<SOAP-ENV:Header></SOAP-ENV:Header>' -
  '<SOAP-ENV:Body>' -
  '<m:GetQuote xmlns="http://www.webserviceX.NET/" xmlns:m="http://www.webserviceX.NET/">' -
  '<symbol>'
  symbol
  '</symbol></m:GetQuote></SOAP-ENV:Body></SOAP-ENV:Envelope>' into
  #request leaving no
*
* For more information about the service have a look at:
* http://www.webservicex.net.
*
request document from 'http://www.webservicex.net/stockquote.asmx'
  with
    header
      name 'Request-Method' value 'POST'
      name 'Content-Type' value 'text/xml'
      name 'SOAPAction' value 'http://www.webserviceX.NET/GetQuote'
    data all #request
    return
      header name ' ' value http-status-text
      page #response
  response #rc
*
if #rc = 200
  examine #response for '<' replace with '<'
  examine #response for '>' replace with '>'
*
  parse xml #response into path #path name #name value #value
    decide on first value of *parse-type
      value 'T'
        #active_name := #name
      value '$'
        decide on first value of #active_name
          value 'Symbol'          ; #reply.symbol := #value
          value 'Last'            ; #reply.last := #value
          value 'Date'            ; #reply.date := #value
          value 'Time'            ; #reply.time := #value
          value 'Change'          ; #reply.change := #value
          value 'Open'            ; #reply.open := #value
          value 'High'            ; #reply.high := #value
          value 'Low'             ; #reply.low := #value
          value 'Volume'          ; #reply.volume := #value
          value 'MktCap'          ; #reply.mktcap := #value
          value 'PreviousClose'   ; #reply.PreviousClose := #value
          value 'PercentageChange'; #reply.PercentageChange := #value
          value 'AnnRange'        ; #reply.annrange := #value
          value 'Earns'           ; #reply.earns := #value
          value 'P-E'             ; #reply.P-E := #value
          value 'Name'            ; #reply.name := #value
          none value ignore
        end-decide
      none value ignore
    end-decide
  end-parse
*
  write #Reply.symbol '-' #reply.name 62T #reply.date #reply.time //
    'Last ..................' #reply.last /
    'Change ................' #reply.change /
    'Open ..................' #reply.open /
    'High ..................' #reply.high /
    'Low ...................' #reply.low /
    'Volume ................' #reply.volume /
    'MktCap ................' #reply.mktcap /
    'Previous Close ........' #reply.previousclose /
    'Percentage Change .....' #reply.percentageChange /
    'Ann Range .............' #reply.annrange /
    'Earns .................' #reply.earns /
    'P-E ...................' #reply.p-e
*
else
  write // 'HTTP-Status:' http-status-text  //
end-if
*
end

Thank you for providing this very useful example.

Accessing the SOAP service requires setting the Request-Method to ‘POST’ and the Content-Type to ‘text/xml’