Consuming web services

txerifftxeriff Member Posts: 501
edited 2017-04-19 in NAV Three Tier
Hi all,
again here.

Im new with web services consumption, hope some1 can help

I have followed this tutorial:

https://moxie4nav.wordpress.com/2015/09/10/call-external-web-service-using-new-cu-1290/

but I guess the wschool example is broken. Thats why im trying to use another from the internet. I get error in both, like xml is not well formed.
any ideas?

thanks!



//Url := 'http://www.w3schools.com/xml/tempconvert.asmx';
//url:='https://flairrugs.metapack.com/dm/services/ConsignmentTrackingService';
//reqText := '' + '10' +'';
url:='http://www.webservicex.net/ConvertTemperature.asmx?op=ConvertTemp';
//reqtext:='Temperature=50&FromUnit=degreeFahrenheit&ToUnit=degreeCelsius';
reqtext:='<Temperature>100</Temperature>'
+'<FromUnit>degreeCelsius</FromUnit>'
+'<ToUnit>degreeFahrenheit</ToUnit>';



// save request text in instream
TempBlob."Primary Key" := 1;
TempBlob.Blob.CREATEOUTSTREAM(ReqBodyOutStream);
ReqBodyOutStream.WRITE(reqText);
TempBlob.Blob.CREATEINSTREAM(ReqBodyInStream);
// run the WebServReqMgt functions to send the request
WebServReqMgt.SetGlobals(ReqBodyInStream,Url,Username,Password);
WebServReqMgt.DisableHttpsCheck;
WebServReqMgt.RUN;
// get the response
WebServReqMgt.GetResponseContent(RespBodyInStream);
ResponseXmlDoc := ResponseXmlDoc.XmlDocument;
ResponseXmlDoc.Load(RespBodyInStream);
MESSAGE(ResponseXmlDoc.InnerXml);



EDIT:

This is what im trying to do now, but I get error 500 (internal server error)


Any ideas how to debug? maybe is cos https?

Credential := Credential.NetworkCredential;
Credential.UserName := 'myusr';
Credential.Password := 'mypwd';

FindURL := 'https://mycomp.metasomething.com/dm/services/ConsignmentTrackingService?method=findParcelTrackingByConsignmentCode&consignmentCode=';
FindURL+='myitemcode';

HttpWebRequest := HttpWebRequest.Create(FindURL);
HttpWebRequest.Timeout := 30000;
HttpWebRequest.UseDefaultCredentials(FALSE);
HttpWebRequest.Credentials := Credential;
HttpWebRequest.Method := 'POST';
HttpWebRequest.ContentType := 'text/xml; charset=utf-8';
HttpWebRequest.Accept := 'text/xml';

MemoryStream := HttpWebRequest.GetRequestStream;
XMLRequestDoc := XMLRequestDoc.XmlDocument;
XMLRequestDoc.Save(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;

HttpWebResponse := HttpWebRequest.GetResponse;
IF HttpWebStatus.Equals(HttpWebResponse.StatusCode,HttpWebStatus.OK) THEN BEGIN
MemoryStream := HttpWebResponse.GetResponseStream;

XMLResponseDoc := XMLResponseDoc.XmlDocument;
XMLResponseDoc.Load(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;

Answers

Sign In or Register to comment.