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