Calling NAV Web Service with Codeunit 1290 (NAV 2016)

mik
Member Posts: 79
Hello,
I'm trying to call a NAV Web Service from NAV with Codeunit 1290. (NAV 2016)
I defined a Codeunit in NAV with a simple Function
SetAndGet(_InParam : Text,VAR _Outparam :Text)
the Problem is, everytime I call the Web Service from NAV with a defined SOAP Request
The Response is always only the wsdl Definition.
Any Idea?
I'm trying to call a NAV Web Service from NAV with Codeunit 1290. (NAV 2016)
I defined a Codeunit in NAV with a simple Function
SetAndGet(_InParam : Text,VAR _Outparam :Text)
the Problem is, everytime I call the Web Service from NAV with a defined SOAP Request
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wst="urn:microsoft-dynamics-schemas/codeunit/wstestmip"> <x:Header/> <x:Body> <wst:SetAndGet> <wst:_InParam>1234</wst:_InParam> <wst:_OutParam/> </wst:SetAndGet> </x:Body> </x:Envelope>
The Response is always only the wsdl Definition.
<definitions targetNamespace="urn:microsoft-dynamics-schemas/codeunit/wstestmip" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:microsoft-dynamics-schemas/codeunit/wstestmip"> <types> <schema elementFormDefault="qualified" targetNamespace="urn:microsoft-dynamics-schemas/codeunit/wstestmip" xmlns="http://www.w3.org/2001/XMLSchema"> <element name="SetAndGet"> <complexType> <sequence> <element minOccurs="1" maxOccurs="1" name="_InParam" type="string" /> <element minOccurs="1" maxOccurs="1" name="_OutParam" type="string" /> </sequence> </complexType> </element> <element name="SetAndGet_Result"> <complexType> <sequence> <element minOccurs="1" maxOccurs="1" name="_OutParam" type="string" /> </sequence> </complexType> </element> </schema> </types> <message name="SetAndGet"> <part name="parameters" element="tns:SetAndGet" /> </message> <message name="SetAndGet_Result"> <part name="parameters" element="tns:SetAndGet_Result" /> </message> <portType name="wstestmip_Port"> <operation name="SetAndGet"> <input name="SetAndGet" message="tns:SetAndGet" /> <output name="SetAndGet_Result" message="tns:SetAndGet_Result" /> </operation> </portType> <binding name="wstestmip_Binding" type="tns:wstestmip_Port"> <binding transport="http://schemas.xmlsoap.org/soap/http" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" /> <operation name="SetAndGet"> <operation soapAction="urn:microsoft-dynamics-schemas/codeunit/wstestmip:SetAndGet" style="document" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" /> <input name="SetAndGet"> <body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" /> </input> <output name="SetAndGet_Result"> <body use="literal" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" /> </output> </operation> </binding> <service name="wstestmip"> <port name="wstestmip_Port" binding="tns:wstestmip_Binding"> <address location="http://client15:7047/DynamicsNAV90/WS/CRONUS%20AG/Codeunit/wstestmip" xmlns="http://schemas.xmlsoap.org/wsdl/soap/" /> </port> </service> </definitions>
Any Idea?
With kind regards
mik
0
Answers
-
Your request document is supposed to only contain the soap request's body content (i.e only those elements belonging to namespace wst above).
Could you show us some code how you use Codeunit 1290, please.0 -
Hi,
I'm facing the same problem. I've used the WebService example form NAV2016 (Letters) which simply transforms a string to uppercase.
Here's my code where I'm using codeunit 1290. In CU1290 I had to Change the TextConstant ContentTypeTxt from "multipart/form-data; charset=utf-8" to "application/xml; charset=utf-8". Otherwise the call failed immedialtely.
<Begin of Code>
baseURL := 'http://localhost:7047/DynamicsNAV/WS/';
systemServiceURL := baseURL + 'CRONUS%20AG/Codeunit/Letters';
BodyTempBlob.Blob.CREATEINSTREAM(BodyContentInputStream);
BodyContentXmlDoc := BodyContentXmlDoc.XmlDocument;
XMLDOMMgt.AddRootElementWithPrefix(BodyContentXmlDoc,'Capitalize','',NamespaceTxt,EnvelopeXmlNode);
XMLDOMMgt.AddElement(EnvelopeXmlNode,'inputstring','abcde',NamespaceTxt,CreatedXmlNode);
BodyTempBlob.Blob.CREATEOUTSTREAM(BodyContentOutputStream);
BodyContentXmlDoc.Save(BodyContentOutputStream);
BodyTempBlob.Blob.CREATEINSTREAM(IStream);
c1290.SetGlobals(IStream,systemServiceURL,'','');
c1290.SetTraceMode(TRUE);
c1290.DisableHttpsCheck;
c1290.SetTimeout(600000);
IF c1290.SendRequestToWebService THEN BEGIN
c1290.GetResponseContent(ResponseInStream);
BodyTempBlob.Blob.CREATEOUTSTREAM(ResponseOutStream);
COPYSTREAM(ResponseOutStream,ResponseInStream);
END ELSE
c1290.ProcessFaultResponse('');
UnicodeEncoding := UnicodeEncoding.UnicodeEncoding(FALSE, FALSE);
BodyTempBlob.Blob.CREATEINSTREAM(InS);
StreamReader := StreamReader.StreamReader(InS, UnicodeEncoding);
MESSAGE(StreamReader.ReadToEnd);
<End of Code>
0 -
Got the same problem, when tried to call Navision Web service through CU1290.
Solution is, to add SOAPAction to BuildWebRequest f-n.
For example:
HttpWebRequest.Headers.Add( 'SOAPAction', 'urn:microsoft-dynamics-schemas/codeunit/GetAmounts');
At the end I added new global variable GlobalSOAPAction to CU1290.1 -
for calling external web services please follow
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 -
Archer89, thank you for Your post. You really helped me, but with NAV Web service as external source it didn't worked without adding SOAPAction.0
-
ok, i will check and give you then feedback.
will be part 3 of that blog post series. ;-)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
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