Calling External Web Services - Blog - SAN Business Solutions

Search
Go to content

Main menu:

Calling External Web Services

Published by in MS Dynamics NAV · 26/1/2017 19:44:00
The following example shows how to communicate with an external web service from MS Dynamics (NAV).
You create a template that you can use to call the web request,  indicating all parameters::
  • Host,
  • Page,
  • Service (optionally with value)



To request data from a host server I use the  .NET Assembly with following method:
CallWebService()
 {
WebRequest request = WebRequest.Create(httpGETstring) as HttpWebRequest;
request.Credentials = CredentialCache.DefaultCredentials;
((HttpWebRequest)request).UserAgent = ".NET Framework Example Client";
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
XmlDocument document = new XmlDocument();
document.Load(dataStream);
document.Save(@responceXmlFileName);
XmlNode node = document.ChildNodes[1];
File.WriteAllText(dataXmlFileName, node.InnerText);
response.Close();
}



Back to content | Back to main menu