Consuming web services

txeriff
Member Posts: 515
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;
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;
0
Answers
-
Hello,
The url https://www.w3schools.com/xml/tempconvert.asmx is working fine. You can check it via your browser directly.
The problem with CU1290 is that it does not understand SOAP 1.2. At least that is my understanding when I followed the same blog. So, if your web service version is 1.2 ... You can't consume it with CU1290
You can find useful comments in the same blog, some of them are mine0 -
nabil.bamoh@hotmail.com wrote: »Hello,
The url https://www.w3schools.com/xml/tempconvert.asmx is working fine. You can check it via your browser directly.
The problem with CU1290 is that it does not understand SOAP 1.2. At least that is my understanding when I followed the same blog. So, if your web service version is 1.2 ... You can't consume it with CU1290
You can find useful comments in the same blog, some of them are mine
thanks for answering
https://www.w3schools.com/xml/tempconvert.asmx?op=CelsiusToFahrenheit
if you go there, enter value, you get error.
thats why I think does not work.
if it does not understand soap 1.2, why he made this example?
0 -
Yes you're right. The web service is down.
I solved my issue by creating a generic soap client. You can check my blog here http://navnab.wordpress.com/2016/12/05/dynamics-nav-generic-soap-client/
I hope this will help you.0 -
nabil.bamoh@hotmail.com wrote: »Yes you're right. The web service is down.
I solved my issue by creating a generic soap client. You can check my blog here http://navnab.wordpress.com/2016/12/05/dynamics-nav-generic-soap-client/
I hope this will help you.
Could you tell me if this is correct?
url:='http://www.webservicex.net/ConvertTemperature.asmx';
//reqtext:='Temperature=50&FromUnit=degreeFahrenheit&ToUnit=degreeCelsius';
reqtext:='<ConvertTemp xmlns="http://www.webserviceX.NET/">'
+'<Temperature>100</Temperature>'
+'<FromUnit>degreeCelsius</FromUnit>'
+'<ToUnit>degreeFahrenheit</ToUnit>';
im trying to run the previous example with another URL
0 -
Hi,
Im still having the problem....
go to the main post of this thread, i have edited
0 -
I saw many blogs and forums adopting the HttpWebRequest 'POST' method. It should work normally. But I'm not a big fan of this method
Which problem do you face exactly?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions