How to call a NAV2016 SOAP (codeunit) Webservice from nav

BEsterhuizen
Member Posts: 13
Hope someone could help me in my quest to be able to consume a NAV SOAP (Codeunit) webservice from another nav instance (both running on NAV2016 RTC so c\al code only).
In NAVinstance1 I have a NAV WebService (Codeunit) that returns me the next available number in a number series. I would like to call this WebService (CU) form NAVinstance2 to be able to assign the next available number in that system (without going into too much detail it is for LSRetail POS terminal requesting HO number sequence)
I have seen posts but nothing seems to work for me..
- https://community.dynamics.com/blogs/post/?postid=471c157c-2cbc-4d40-bd3d-da3d2e71cc14
- https://vjeko.com/2012/09/30/web-services-black-belt-consuming-nav-web-services-using-pure-cal/
In NAVinstance1 I have a NAV WebService (Codeunit) that returns me the next available number in a number series. I would like to call this WebService (CU) form NAVinstance2 to be able to assign the next available number in that system (without going into too much detail it is for LSRetail POS terminal requesting HO number sequence)
I have seen posts but nothing seems to work for me..
- https://community.dynamics.com/blogs/post/?postid=471c157c-2cbc-4d40-bd3d-da3d2e71cc14
- https://vjeko.com/2012/09/30/web-services-black-belt-consuming-nav-web-services-using-pure-cal/
0
Answers
-
Ok have managed to get this working....please see below using https://navfreak.com/2017/02/25/dynamics-nav-how-to-consume-an-external-soap-web-service-with-netdotnet-interop/
sb := sb.StringBuilder();
sb.Append('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="urn:microsoft-dynamics-schemas/codeunit/GET_HO_NumberSeries">');
sb.Append('<soapenv:Header>');
//sb.Append('<test:userPassword>xxxxxxxx</test:userPassword>');
//sb.Append('<test:userId>xxxx</test:userId>');
sb.Append('</soapenv:Header>');
sb.Append('<soapenv:Body>');
sb.Append('<get:HOReturnNextNumber>');
sb.Append('<get:noSeriesCode>T-GIFTCARD</get:noSeriesCode>');
sb.Append('<get:errorMsg></get:errorMsg>');
sb.Append('<get:nextNumberSeriesNumber></get:nextNumberSeriesNumber>');
sb.Append('</get:HOReturnNextNumber>');
sb.Append('</soapenv:Body>');
sb.Append('</soapenv:Envelope>');
//XMLRequest
// complete sericve URL
uriObj := uriObj.Uri('http://nav-test.xxxxxxxx.local:8047/xxxxxxUAT/WS/xxxx LIVE/Codeunit/GET_HO_NumberSeries');
lgRequest := lgRequest.CreateDefault(uriObj);
lgRequest.Method := 'POST';
lgRequest.ContentType := 'text/xml';
// only use the page name form the URL
lgRequest.Headers.Add('SOAPAction','GET_HO_NumberSerie');
// XMLResponse
lgRequest.Credentials := credentials.DefaultCredentials;
lgRequest.Timeout := 120000;
stream := stream.StreamWriter(lgRequest.GetRequestStream(),ascii.ASCII()); // falling over on this line
stream.Write(sb.ToString());
stream.Close();
lgReponse := lgRequest.GetResponse();
str := lgReponse.GetResponseStream();
reader := reader.XmlTextReader(str);
document := document.XmlDocument();
document.Load(reader);
reader.Close();
str.Close();
Filename := 'c:\temp\Result_' + FORMAT(TODAY,0,9) + '_' + FORMAT(CREATEGUID) + '.xml';
document.Save(Filename);
Note that you are using the mscorlib so you need to write it manually in the Subtype and then tab to expose the methods.....(caught me until someone pointed it out to me) System you need to just select the System v4 and then you will see the system exposed methods too.
Name DataType Subtype
**Type mscorlib to find core libary*** Integer
sb DotNet System.Text.StringBuilder.'mscorlib'
stream DotNet System.IO.StreamWriter.'mscorlib'
str DotNet System.IO.Stream.'mscorlib'
ascii DotNet System.Text.Encoding.'mscorlib'
**.Net system only and then look for rest*** Integer
uriObj DotNet System.Uri.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
lgRequest DotNet System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
lgReponse DotNet System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
reader DotNet System.Xml.XmlTextReader.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
document DotNet System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
credentials DotNet System.Net.CredentialCache.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Filename Text
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
- 321 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