# Using a web service from Natural on mainframe

**URL:** <https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Web-and-XML-Technology\
**Created:** [June 21, 2012, 5:34pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799 "2012-06-21T17:34:33Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gil\_Wildin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@Gil\_Wildin](https://techcommunity.softwareag.com/u/Gil_Wildin)\
**Post date:** [June 21, 2012, 5:34pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/1 "2012-06-21T17:34:33Z")

</div>

Hello, I am trying to use a web service ([http://www.webservicex.net/globalweather.asmx](http://www.webservicex.net/globalweather.asmx) as an example) from Natural on the mainframe. I am using the REQUEST DOCUMENT statement. I can connect ok and get a 200 http return code when I use this code:

```auto
REQUEST DOCUMENT FROM #FROM              
 * WITH                                   
 * HEADER #OUT-HDR 'POST'               
 * DATA #DOCUMENT 'POST'                
   RETURN                                 
    HEADER ALL #HEADER        
    NAME 'Content-Type' #DOC-CHARSET   
   PAGE #PAGE                             
 RESPONSE #RC                             
   GIVING #RTERR                          
```

I seem to be getting the html page back. What I want to do is send it a SOAP envelope with the request to get the weather for Tokyo, Japan. I did this successfully using the SoapUI tool, and I copied the SOAP request into my Natural code. So I uncommented the WITH, HEADER and DATA lines. BUt then, I get a 415 - HTTP/1.1 415 Unsupported Media Type error. Any clues? I am fairly new to web services and SOAP. Here is my SOAP request:

```auto
COMPRESS                                                     
'<soapenv:Envelope '                                         
'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'  
'xmlns:web="http://www.webserviceX.NET">'                    
' <soapenv:Header/>'                                       
' <soapenv:Body>'                                          
' <web:GetWeather>'                                     
' <!--Optional:-->'                                  
' <web:CityName>tokyo</web:CityName>'                
' <!--Optional:-->'                                  
' <web:CountryName>Japan</web:CountryName>'          
' </web:GetWeather>'                                    
' </soapenv:Body>'                                         
'</soapenv:Envelope>'                                        
INTO #DOCUMENT       
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 21, 2012, 9:27pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/2 "2012-06-21T21:27:35Z")

</div>

Try

```auto
define data local
1 #FROM (A) DYNAMIC
1 #DOCUMENT (A) DYNAMIC
1 #HEADER (A) DYNAMIC
1 #PAGE (A) DYNAMIC
1 #DOC-CHARSET (A) DYNAMIC
1 #RETERR (I4)
1 #RC (I4)   
End-define        
*                       
#FROM := 'http://www.webservicex.net/globalweather.asmx'
*                      
COMPRESS
'<?xml version="1.0" encoding="utf-8"?>' 
'<soap:Envelope'                                       
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"'             
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
' <soap:Body>'                                                                       
' <GetWeather xmlns="http://www.webserviceX.NET">'    
' <CityName>tokyo</CityName>'                                     
' <CountryName>Japan</CountryName>'                       
' </GetWeather>'                                                               
' </soap:Body>'                                                                    
'</soap:Envelope>'                                                                
INTO #DOCUMENT                                                                  
*                                                                                             
#RC := *LENGTH(#DOCUMENT)                                              
*                                                                                             
REQUEST DOCUMENT FROM #FROM                                        
  WITH                                                                                     
    HEADER 'Content-Type' 'text/xml;charset=UTF-8'               
           'Content-Length' #RC                                                  
           'SOAPAction' 'http://www.webserviceX.NET/GetWeather' 
           'Request-method' 'POST'
    DATA ALL #DOCUMENT       
    RETURN                                 
       HEADER ALL #HEADER 
       PAGE #PAGE                            
       RESPONSE #RC                       
       GIVING #RETERR
*
WRITE #RC #RETERR 
END
```

---

<div class="post-metadata">

**Author:** ![Gil\_Wildin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@Gil\_Wildin](https://techcommunity.softwareag.com/u/Gil_Wildin)\
**Post date:** [June 21, 2012, 9:43pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/3 "2012-06-21T21:43:49Z")

</div>

Thanks, Woflgang, I’ll try it later on today. It looks good, and I’ll post how it goes.

---

<div class="post-metadata">

**Author:** ![Gil\_Wildin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@Gil\_Wildin](https://techcommunity.softwareag.com/u/Gil_Wildin)\
**Post date:** [June 21, 2012, 10:39pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/4 "2012-06-21T22:39:45Z")

</div>

I get this output:

```auto
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/st
 <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>??
 HTTP Error 400. The request has an invalid header name.</p>??</BODY></HTML>??  
HTTP/1.1 400 Bad Request?Content-Type: text/html; charset=us-ascii?Server: Micr
GMT?Connection: close?Content-Length: 339??                                     
```

I think the 400 isn’t really accurate, as when I commented out the last two headers, I still got the 400 error. When I comment out 3 headers, I get a 405 because it is doing a PUT. So, I think we’re closer, but not quite there.

```auto
REQUEST DOCUMENT FROM #FROM                                          
  WITH                                                               
    HEADER 'Content-Type' 'text/xml;charset=utf-8'                  
* 'Content-Length' #L                                       
* 'SOAPAction' 'http://www.webserviceX.NET/GetWeather'   
* 'Request-method' 'POST'                                   
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 21, 2012, 11:22pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/5 "2012-06-21T23:22:52Z")

</div>

One note:

I tried this from an OpenSystems Natural (Linux in that case), and it works as  
posted, so yes, it can’t be much, but I can’t try from a mainframe Natural at  
the moment.

I assume it’s an encoding issue, what’s your CP parameter setting ?

---

<div class="post-metadata">

**Author:** ![Gil\_Wildin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@Gil\_Wildin](https://techcommunity.softwareag.com/u/Gil_Wildin)\
**Post date:** [June 22, 2012, 2:49pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/6 "2012-06-22T14:49:15Z")

</div>

WRITE ‘=’ \*CODEPAGE gives me this:

CODEPAGE: IBM01140  
If it works on Linux, I think you’re right about the encoding. I’ll try a few things this morning.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 22, 2012, 2:53pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/7 "2012-06-22T14:53:46Z")

</div>

I’d try changing it to

DATA ALL #DOCUMENT ENCODED CODEPAGE ‘UTF-8’

---

<div class="post-metadata">

**Author:** ![Gil\_Wildin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@Gil\_Wildin](https://techcommunity.softwareag.com/u/Gil_Wildin)\
**Post date:** [June 22, 2012, 3:19pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/8 "2012-06-22T15:19:28Z")

</div>

I tried that and still seem to get the 400 return code. I’ll continue to experiment.

```auto
REQUEST DOCUMENT FROM #FROM                                         
  WITH                                                              
    HEADER 'Content-Type' 'text/xml;charset=utf-8'                 
           'Content-Length' #L                                      
           'SOAPAction' 'http://www.webserviceX.NET/GetWeather'  
           'Request-method' 'POST'                                  
    DATA ALL #DOCUMENT                                           
      ENCODED CODEPAGE 'UTF-8'                                      
  RETURN                                                            
   HEADER ALL #HEADER                                   
   NAME 'Content-Type' #DOC-CHARSET                              
  PAGE #PAGE                                                        
RESPONSE #RC                                                        
  GIVING #RTERR                                            
```

MORE  
HTTP/1.1 400 Bad Request?Content-Type: text/html; charset=us-ascii?Server: Micr  
GMT?Connection: close?Content-Length: 339??

* * *

HELLO AGAIN  
??à|äèß&á?çè(\<?&íâ\<ñä?????ï?ä??àèà?çè(\<???????á+??ÇÈÈø???ÏÏÏ?Ï???ÊÅ?èê?ÇÈ\_%??ËÈ ?(áè ?çèè&?áéíñî??ä?\>ÈÁ\>È?è`øÁ??ä?\>ÈÁ\>È??ÈÁÌÈ?ÇÈ\_%??ÄÇ/ÊËÁÈ?ÍË?/ËÄÑÑ???çá à???  
çèè&?áÊÊ?Ê???èÇÁ?ÊÁÉÍÁËÈ?Ç/Ë?/\>?Ñ\>Î/%ÑÀ?ÇÁ/ÀÁÊ?\>/\_Á???ø???â|àß???çè(\<???

* * *

* * *

CODEPAGE: IBM01140  
BEFORE PARSE

 \<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/st ??

HTTP Error 400. The request has an invalid header name.

????

* * *

---

<div class="post-metadata">

**Author:** ![Gil\_Wildin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@Gil\_Wildin](https://techcommunity.softwareag.com/u/Gil_Wildin)\
**Post date:** [June 22, 2012, 3:41pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/9 "2012-06-22T15:41:23Z")

</div>

YAHOO! I got it to return the weather info! Here is some of the code and the unparsed output. Thanks for all your help!

```auto
REQUEST DOCUMENT FROM #FROM                                             
   WITH                                                                  
     HEADER 'Content-Type' 'text/xml;charset=utf-8'                     
 * 'Content-Length' #L                                          
 * 'SOAPAction' 'http://www.webserviceX.NET/GetWeather'      
            'Request-method' 'POST'                                      
     DATA ALL #DOCUMENT                                               
       ENCODED CODEPAGE 'UTF-8'                                          
   RETURN                                                                
    HEADER ALL #HEADER                                       
    NAME 'Content-Type' #DOC-CHARSET                                  
   PAGE #PAGE                                                            
 RESPONSE #RC                 
```

HELLO  
#L: 425 #RC: 200

```auto
CODEPAGE: IBM01140                                                             
  BEFORE PARSE                                                                  
 <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas
 w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><s
 webserviceX.NET"><GetWeatherResult><?xml version="1.0" encoding="utf-16"?&gt
 International Airport, Japan (RJTT) 35-33N 139-47E 8M</Location>?? <T
 UTC</Time>?? <Wind> from the SSE (150 degrees) at 7 MPH (6 KT):0&l
 mile(s):0</Visibility>?? <SkyConditions> mostly cloudy</SkyCond
 Temperature>?? <DewPoint> 62 F (17 C)</DewPoint>?? <Relativ
 Pressure> 29.74 in. Hg (1007 hPa)</Pressure>?? <Status>Success&
 GetWeatherResult></GetWeatherResponse></soap:Body></soap:Envelope>             
```

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [June 22, 2012, 4:23pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/10 "2012-06-22T16:23:34Z")

</div>

Small warning !  
I thought this was a good example and continued with parsing (- which you are probably already at?)  
And this is not a walk in the park, since there are actually TWO xml documents, a soap envelope in UTF-8 and the actual weather report in UTF-16.  
The natural parse statement tries to sort out the encoding but you will get some strange errors ☹

“3415 conversion result is truncated”  
probably because of the 2byte UTF-16.

Haven’t figured out yet how to handle this smoothly ☹

Perhaps Wolfgang has some ideas ?  
Finn

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 22, 2012, 4:25pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/11 "2012-06-22T16:25:18Z")

</div>

Just to confirm, this works for me on Linux as well, when I played with it I jumped between  
400 & 415 errors so I stopped with a combination that finally worked 😉

Still strange it doesn’t work the way I originally posted it, so there are probably subtle  
differences at some layer.

Glad to see it works for you, finally, though !

---

<div class="post-metadata">

**Author:** ![Gil\_Wildin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@Gil\_Wildin](https://techcommunity.softwareag.com/u/Gil_Wildin)\
**Post date:** [June 22, 2012, 4:34pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/12 "2012-06-22T16:34:10Z")

</div>

Hello Finn,  
When I use this to parse it,

```auto
ASSIGN #CP = *CODEPAGE                                     
MOVE ENCODED #PAGE TO #PAGE CODEPAGE #CP                   
WRITE ' BEFORE PARSE'                                      
PRINT #DISPLAY-DOC                                         
  / '_'(79)                                                
EJECT                                                      
PARSE XML #PAGE INTO PATH #PATH NAME #NAME VALUE #VALUE    
  PRINT #PATH / 'NAME=' #NAME / 'VALUE=' #VALUE / '_'(79)  
END-PARSE                                                  
```

I get the following. it just leaves the weather report all in one big glob. No errors reported, though. I am running on the mainframe.

```auto
soap:Envelope/soap:Body/GetWeatherResponse/GetWeatherResult/$                  
 NAME=                                                                          
 VALUE= <?xml version="1.0" encoding="utf-16"?>?<CurrentWeather>? <Location>Tok
 47E 8M</Location>? <Time>Jun 22, 2012 - 10:00 AM EDT / 2012.06.22 1400 UTC</Ti
 KT):0</Wind>? <Visibility> greater than 7 mile(s):0</Visibility>? <SkyConditi
 68 F (20 C)</Temperature>? <DewPoint> 62 F (17 C)</DewPoint>? <RelativeHumidi
 (1007 hPa)</Pressure>? <Status>Success</Status>?</CurrentWeather>             
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 22, 2012, 4:36pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/13 "2012-06-22T16:36:49Z")

</div>

What happens when you add an ENCODED to the RETURN PAGE ?

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [June 25, 2012, 3:35pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/14 "2012-06-25T15:35:46Z")

</div>

Found a work-around - or actually two !  
The problem appears to be that the content of the “GetWeatherResult” tag says it is utf-16, but in fact is just utf-8 !

So when Natural tries to parse it (as it should) as utf-16 you run into problems ☹  
What I ghave done is to have two parse statements:  
One for getting the “body” and one for parsing it after converting it with one of the options below:

- Option 1 - change XML encoding-info in ?xml tag  
EXAMINE #PAGE2 FOR ‘utf-16’ REPLACE WITH ‘utf-8’

- Option 2 make the actual encoding match the ?xml encoding-info  
MOVE ENCODED #PAGE2 CODEPAGE ‘utf-8’ TO #PAGE2 CODEPAGE ‘utf-16’

See full working example (for windows!) in the attachment.

Finn  
PS After strugling a with this I googled “GetWeatherResult utf-8 utf-16” and found that I was not the first 😉  
[WEATHER.txt](https://techcommunity.softwareag.com/uploads/short-url/7ItOr5R5GX03qEFgi6tXEx5Wl9a.txt) (2.91 KB)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 25, 2012, 4:11pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/15 "2012-06-25T16:11:41Z")

</div>

Thanks, Finn,

I’ve just posted a code sample with a working (cross-platform) example,  
provided by R&D, I’m just waiting for the sample to get cleared by the admins  
before I can refer to it here.

Synopsis:

- ENCODING required on the REQUEST
- avoid playing with encodings on the response and let Natural do the job

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 25, 2012, 6:08pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/16 "2012-06-25T18:08:34Z")

</div>

The code sample is&nbsp;&nbsp;&nbsp;[here](http://communities.softwareag.com/ecosystem/communities/codesamples/natural/general/SAMPLE-20120625151847657.html)

Any problems with it - please let me know !

---

<div class="post-metadata">

**Author:** ![Suman\_Suman](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@Suman\_Suman](https://techcommunity.softwareag.com/u/Suman_Suman)\
**Post date:** [August 23, 2016, 5:14pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/17 "2016-08-23T17:14:04Z")

</div>

> [@Wolfgang Winter](#):
>
> The code sample is&nbsp;&nbsp;&nbsp;[here](http://communities.softwareag.com/ecosystem/communities/codesamples/natural/general/SAMPLE-20120625151847657.html)
> 
> Any problems with it - please let me know !

* * *

Hi,

I found this thread for exactly what I was looking for. I tried the code on mainframes however I am getting runtime error ‘NAT0954 Abnormal termination AEY9 during program execution.’

Please can you help me with this, how to get a successful run of this program?

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:02pm UTC](https://techcommunity.softwareag.com/t/using-a-web-service-from-natural-on-mainframe/100799/18 "2021-04-02T15:02:05Z")

</div>


