Rashed Amini

The ara3n weblog

Webservice with WinHTTP

24th April 2008

There are several howto on mibuso on how to consume webservices. Most of these examples for example
http://www.mibuso.com/forum/viewtopic.php?t=23618

You can also use WinHTTP
‘Microsoft WinHTTP Services, version 5.1′.WinHttpRequest

Why would you want to use WinHTTP, well it has a SetTimeouts function that allows you to stop waiting for a webservice. So navision doesn’t stop working if you don’t receive a message back.

WinHTTP.Open('POST','http://www.webservicex.net/CurrencyConvertor.asmx',0);
WinHTTP.SetRequestHeader('Content-type','text/xml');
WinHTTP.SetRequestHeader('SOAPAction','http://www.webserviceX.NET/ConversionRate');

WinHTTP.SetTimeouts(1000,1000,1000,1000);

WinHTTP.Send(XmlDoc);
WinHTTP.WaitForResponse(1000);

XmlDoc.async := FALSE;
XmlDoc.load(WinHTTP.ResponseBody);

IF WinHTTP.Status 200 THEN
ERROR('Http Error ' + ' ' + FORMAT(WinHTTP.Status) + ': ' + WinHTTP.StatusText);

One Response to “Webservice with WinHTTP”

  1. Samet Sorgut Says:

    WaitForResponse value has to be in seconds not in milliseconds.
    WaitForResponse(1000) waits for 1000 seconds which means a wait time of 16 minutes 40 seconds.

    SetTimeouts values are in milliseconds but WaitForResponse is in seconds.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word