Hello, I am trying to use a web service (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:
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:
<!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.
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'
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 ?
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
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.
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 (2.91 KB)
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
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?