Call a NAV Exposed Web Service in NAV using CU1290 in NAV2017
jordi79
Member Posts: 285
Hi All,
I have created a CU that just returns UPPERCASE of a supplied parameter, and I have exposed this CU as a web service.
The problem is that I am having problems in calling this web service, and using it in NAV. I have taken a look at CU248 "VAT Lookup Ext. Data Hndl.", and have adapted this to call my own exposed Web Service. But I seem to hit into endless errors. I have taken a look at some of the examples in this site and in the web, but when I try them, all seem to hit into errors.
When running code below, I hit into the error:
When I debugged the xml result, it is just the whole xml file similar to entering the Web service linke which is --> 'http://aws01:7047/DynamicsNAV100/WS/CRONUS International Ltd./Codeunit/WS_Exposed_CU' in the browser. But it should return a smaller xml file with the result.
My new CU adapted from CU248. By the way, I tested CU248, and it is working. But this CU calls an external web service (EU VAT validation web service), and not a NAV exposed web service. Also, I had errors coming from CU1290 with regards to 'multipart/form-data; charset=utf8', but I made some changes to CU1290 to bypass this error.
As usual, thanks for taking the time to look into this.
I have created a CU that just returns UPPERCASE of a supplied parameter, and I have exposed this CU as a web service.
The problem is that I am having problems in calling this web service, and using it in NAV. I have taken a look at CU248 "VAT Lookup Ext. Data Hndl.", and have adapted this to call my own exposed Web Service. But I seem to hit into endless errors. I have taken a look at some of the examples in this site and in the web, but when I try them, all seem to hit into errors.
When running code below, I hit into the error:
The expected data was not received from the web service
When I debugged the xml result, it is just the whole xml file similar to entering the Web service linke which is --> 'http://aws01:7047/DynamicsNAV100/WS/CRONUS International Ltd./Codeunit/WS_Exposed_CU' in the browser. But it should return a smaller xml file with the result.
My new CU adapted from CU248. By the way, I tested CU248, and it is working. But this CU calls an external web service (EU VAT validation web service), and not a NAV exposed web service. Also, I had errors coming from CU1290 with regards to 'multipart/form-data; charset=utf8', but I made some changes to CU1290 to bypass this error.
OBJECT Codeunit 99998 WS Test 4
{
OBJECT-PROPERTIES
{
Date=21-12-16;
Time=[ 1:18:40 AM];
Modified=Yes;
Version List=NAVW110.0;
}
PROPERTIES
{
OnRun=BEGIN
//VATRegistrationLog := Rec;
ExecWebService(TRUE);
//Rec := VATRegistrationLog;
END;
}
CODE
{
VAR
NamespaceTxt@1003 : TextConst 'ENU=urn:microsoft-dynamics-schemas/codeunit/WS_Exposed_CU';
VATRegistrationLog@1000 : Record 249;
VATRegistrationLogMgt@1002 : Codeunit 249;
LOCAL PROCEDURE ExecWebService@7(ShowErrors@1000 : Boolean);
VAR
RequestBodyTempBlob@1002 : Record 99008535;
BEGIN
RequestBodyTempBlob.INIT;
SendRequestToVatRegistrationService(RequestBodyTempBlob,ShowErrors);
MessageXMLOutput(RequestBodyTempBlob);
//COMMIT;
END;
LOCAL PROCEDURE SendRequestToVatRegistrationService@1(VAR BodyTempBlob@1004 : Record 99008535;ShowErrors@1003 : Boolean);
VAR
GeneralLedgerSetup@1005 : Record 98;
SOAPWebServiceRequestMgt@1001 : Codeunit 1290;
ResponseInStream@1002 : InStream;
InStream@1006 : InStream;
ResponseOutStream@1008 : OutStream;
BEGIN
PrepareSOAPRequestBody(BodyTempBlob);
BodyTempBlob.Blob.CREATEINSTREAM(InStream);
GeneralLedgerSetup.GET;
//IF GeneralLedgerSetup."VAT Reg. No. Validation URL" = '' THEN
// ERROR(MissingWebServiceURLErr);
SOAPWebServiceRequestMgt.SetGlobals(
InStream,
'http://aws01:7047/DynamicsNAV100/WS/CRONUS%20International%20Ltd./Codeunit/WS_Exposed_CU','','');
SOAPWebServiceRequestMgt.DisableHttpsCheck;
SOAPWebServiceRequestMgt.SetTimeout(60000);
IF SOAPWebServiceRequestMgt.SendRequestToWebService THEN BEGIN
SOAPWebServiceRequestMgt.GetResponseContent(ResponseInStream);
BodyTempBlob.Blob.CREATEOUTSTREAM(ResponseOutStream);
COPYSTREAM(ResponseOutStream,ResponseInStream);
END ELSE
IF ShowErrors THEN
SOAPWebServiceRequestMgt.ProcessFaultResponse('');
END;
LOCAL PROCEDURE PrepareSOAPRequestBody@12(VAR BodyTempBlob@1000 : Record 99008535);
VAR
XMLDOMMgt@1006 : Codeunit 6224;
BodyContentInputStream@1004 : InStream;
BodyContentOutputStream@1005 : OutStream;
BodyContentXmlDoc@1003 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
EnvelopeXmlNode@1012 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
CreatedXmlNode@1001 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
BEGIN
BodyTempBlob.Blob.CREATEINSTREAM(BodyContentInputStream);
BodyContentXmlDoc := BodyContentXmlDoc.XmlDocument;
//XMLDOMMgt.AddRootElementWithPrefix(BodyContentXmlDoc,'checkVat','',NamespaceTxt,EnvelopeXmlNode);
XMLDOMMgt.AddRootElementWithPrefix(BodyContentXmlDoc,'ReturnCaps','',NamespaceTxt,EnvelopeXmlNode);
XMLDOMMgt.AddElement(EnvelopeXmlNode,'inStr','this should be in caps',NamespaceTxt,CreatedXmlNode);
//XMLDOMMgt.AddElement(EnvelopeXmlNode,'vatNumber',VATRegistrationLog.GetVATRegNo,NamespaceTxt,CreatedXmlNode);
CLEAR(BodyTempBlob.Blob);
BodyTempBlob.Blob.CREATEOUTSTREAM(BodyContentOutputStream);
BodyContentXmlDoc.Save(BodyContentOutputStream);
//>> to debug output xml
MESSAGE(FORMAT(BodyContentXmlDoc.InnerXml));
//<< to debug output xml
END;
LOCAL PROCEDURE MessageXMLOutput@4(ResponseBodyTempBlob@1000 : Record 99008535);
VAR
XMLDOMManagement@1001 : Codeunit 6224;
XMLDocOut@1012 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
InStream@1009 : InStream;
BEGIN
ResponseBodyTempBlob.Blob.CREATEINSTREAM(InStream);
XMLDOMManagement.LoadXMLDocumentFromInStream(InStream,XMLDocOut);
MESSAGE(FORMAT(XMLDocOut.InnerXml));
//VATRegistrationLogMgt.LogVerification(VATRegistrationLog,XMLDocOut,NamespaceTxt);
END;
BEGIN
END.
}
}
As usual, thanks for taking the time to look into this.
1
Answers
-
check out
https://moxie4nav.wordpress.com/2015/09/10/call-external-web-service-using-new-cu-1290/
https://moxie4nav.wordpress.com/2016/07/03/call-external-web-service-using-cu-1290-part-2/
best regards
Franz Kalchmair, MVP
Alias: Jonathan Archer
please like / agree / verify my answer, if it was helpful for you. thx.
Blog: http://moxie4nav.wordpress.com/0 -
I found out I had errors because I was running on multi tenant. And the URL for webservices is different for multi tenant.0
-
thanks for the post, helped me lot0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
