Call external web service using new CU 1290

With Nav 2015 there came some new objects. One of them is CU 1290 “Web Service Request Mgt.”.

Here is a short sample, how to use it:

the variables:
url : Text
reqText : Text
webServReqMgt : Codeunit : Web Service Request Mgt.
reqBodyOutStream : OutStream
reqBodyInStream : InStream
username : Text
password : Text
respBodyInStream : InStream
responseXmlDoc : DotNet : System.Xml.XmlDocument.’System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′
tempBlob : Record : TempBlob
action : Text

the code:
url := ´http://www.dneonline.com/calculator.asmx´;
//set body content of soap envelope
reqText := ´<add><inta>1</inta><intb>2</intb></add>´;
action := ´http://tempuri.org/Add´;

// 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.SetCustomGlobals(TRUE,action,FALSE,”,”);
webServReqMgt.DisableHttpsCheck;
webServReqMgt.SetTraceMode(TRUE); //to check the xml messages
webServReqMgt.SendRequestToWebService;

// get the response
webServReqMgt.GetResponseContent(respBodyInStream);
responseXmlDoc := responseXmlDoc.XmlDocument;
responseXmlDoc.Load(respBodyInStream);
MESSAGE(responseXmlDoc.InnerXml);

As you can see Username and Password are empty. That’s ok, if you run the call within the same AD or like in most cases, the target web service needs no authentication.

Changes in CU 1290
Using Credentials
for the case, you want to use credentials, do the following:
add local variable
NetCredential : DotNet : System.Net.NetworkCredential.’System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

fct. BuildWebRequest:
replace
HttpWebRequest.UseDefaultCredentials := TRUE;
by
IF (GlobalUsername ”) AND (GlobalPassword ”) THEN BEGIN
  NetCredential := NetCredential.NetworkCredential(GlobalUsername,GlobalPassword);
  HttpWebRequest.Credentials := NetCredential;
END ELSE
  HttpWebRequest.UseDefaultCredentials := TRUE;

replace
HttpWebRequest.ContentType := ContentTypeTxt;
by
HttpWebRequest.ContentType := ‘text/xml;charset=utf-8’;

ContentTypeTxt has value “multipart/form-data; charset=utf-8”.
the web service call won’t work with that content type.

add these lines:
IF SoapAction <> ” THEN
  HttpWebRequest.Headers.Add(‘SOAPAction’, SoapAction);

new fct. SetCustomGlobals(useXmlMsgTypePar: Boolean;soapActionPar : Text;skipNsPar : Boolean;nsPrefixPar : Text;nsTxtPar : Text)
  UseXmlMsgType := useXmlMsgTypePar;
  SoapAction := soapActionPar;
  SkipDefaultNamespaces := skipNsPar;
  CustomNamespacePrefix := nsPrefixPar;
  CustomNamespaceTxt := nsTxtPar;

cheers

Dynamics Connector for NAV vs. 3.4 is released

Hi all,

Dynamics Connector for NAV vs. 3.4 (V3 CU4) was released on Dec./10/2014. The new Dynamics Connector provides an integration between Microsoft Dynamics CRM 2013 or CRM 2015 and Microsoft Dynamics NAV 2009 R2, NAV 2013, NAV 2013 R2 or NAV 2015. For integration of CRM 2011 use Connector V3 (Download section).

System Requirements:
.NET Framework 4.5.2
For Microsoft Dynamics NAV 2009 R2 KB 2597312 is needed.
For Microsoft Dynamics NAV 2009 R2 KB 2721512 is needed.

You can download the Connector from here.