Remove Attribute – Soap Request XML(XmlPort)

 

Hey Friends,

We all know how to remove Namespaces from the XML if we want to import it from NAV XmlPort, I just faced a situation where I was using XmlPort to send Soap Request with Default Namespace. Using default namespace creates an attribute something like this (xmlns:xx=”http://xx.org/soap/envelope/”) in the soap::Body which basically disrespects the Soap request as sometimes it’s not needed in the protocol of the soap request. So now if we use Remove Namespace code then it will remove the namespaces from the entire XML i.e. Soap:Header as well. In this case here is the code that you need to write to just eliminate it from the soap:Body.

untitled

Now when you load this BigTextOutputValue to your XmlDoc, you will have a XML with no Attributes in the Soap:Body and you can send this as a Soap Request via HTTP.

BigTextVaue  –   DateType  – BigText

BigTextOutputVaue  –   DateType  – BigText

CHEERS.

Advertisements

Remove Namespace – Web Service Response (Automation Variable)

Hey Everybody,

This Post is about How to Import directly an XML which is coming as Web-Service from different platform like .NET. Whenever we get a response from a .NET Service we usually get Namespaces coming as enclosed in it. Now being a NAV developer  it’s something which becomes a barrier to us while getting it directly Imported from NAV XML Ports. So here we are to how get rid from this.

What exactly you need to do is you have to write below piece of code with the same DotNet variable references which you have used while getting sending a Request.

Capture

When you will save this in the last call your response will get saved without Namespaces. Now you can directly Import it Via your XML Port.

XmlStyleSheet – ‘Microsoft XML, v6.0’.DOMDocument60

XMLSourceDocument – ‘Microsoft XML, v6.0’.DOMDocument60

XMLDestinationDocument – ‘Microsoft XML, v6.0’.DOMDocument60

CHEERS.

Remove Namespace – Web Service Response (DotNet Variable)

Hey Everybody,

This Post is about How to Import directly an XML which is coming as Web-Service from different platform like .NET. Whenever we get a response from a .NET Service we usually get Namespaces coming as enclosed in it. Now being a NAV developer  it’s something which becomes a barrier to us while getting it directly Imported from NAV XML Ports. So here we are to how get rid from this.

What exactly you need to do is you have to write below piece of code with the same DotNet variable references which you have used while getting sending a Request.

Capture

When you will save this in the last call your response will get saved without Namespaces. Now you can directly Import it Via your XML Port.

XmlStyleSheet – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

XMLSourceDocument – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

XMLDestinationDocument – MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

CHEERS.

String Comparison – Use DotNet Variable

 

Hey Friends,

I guess many Developers might have had faced this Issue, Whenever we used to compare a Text variable in CAL Coding something like –

Capture1

 

 

 

 

We do face Issues like System is not giving Error even CalTextVariable contains a Blank value. Majority times this Issues comes when there is an Integration between NAV and some .NET Portals. Reason behind this issue is, A NULL value is never considered as a Blank value OR even you can say the White Spaces. So this Line of Code is never a Full Proof solution to handle these cases.

But Instead of the above Line of Code If we just Introduce a .Net Variable and write below line of Code then this turns out to be Full Proof Solution.

Capture

This Piece of Code will handle each Probability that might ever we skip while Coding.

DotNetStringVariable – System.String.’mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

CalTextVariable  – CAL Text Variable.

CHEERS

Disable specific Keyboard Keys – Single Line of Code

 

Hey Friends,

I saw many people asking how to disable specific keys from Keyboards like for example How to Disable Enter Key , Though I never got this need 🙂 but eventually requirements has no limits hence I decided to find it out and introduce it here in my Blog.

Capture

InputFromKeyboard – System.Windows.Input.Keyboard.’PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′

InputKey – System.Windows.Input.Key.’WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′

Enable RunOnClient Property as Yes for both the.NET Variables

You just need to write the above code highlighted, What it will do is when the confirmation Dialogues pops up then you need to Press Yes from MOUSE instead of the Enter Key from Keyboard to execute the further piece of Codes. If you will Press Enter from Keyboard then EXIT statement will Run and system will leave the execution

CHEERS

Start Windows Service from NAV

 

ServiceController := ServiceController.ServiceController;

ServiceController.ServiceName(‘Service Name’);

ServiceController.DisplayName(‘Display Name’);

ServiceController.MachineName(‘Machine Name’);

ServiceController.Start;

ServiceController.WaitForStatus(ServiceController.Status.Running);

ServiceController.Refresh;

MESSAGE(TEXT001);

 

TEXT001 – Service Started

ServiceController –   DOTNET   – 

System.ServiceProcess.ServiceController.’System.ServiceProcess,  Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

 

Consume .NET Webservice (DotNet Data Type)

 

IF ISNULL(DotNetXmlDoc) THEN
DotNetXmlDoc := DotNetXmlDoc.DOMDocumentClass;

IF ISNULL(DotNetXmlHttp) THEN
DotNetXmlHttp := DotNetXmlHttp.XMLHTTPRequestClass;

DotNetXmlHttp.open(‘POST’,’URL’,0,0,0);

DotNetXmlHttp.SetRequestHeader(‘Host’,’ServerName);

DotNetXmlHttp.SetRequestHeader(‘Content-Type’,’text/xml; charset=utf-8′);

DotNetXmlHttp.SetRequestHeader(‘Content-Length’,’Length’);

DotNetXmlHttp.SetRequestHeader(‘SOAPAction’,’http://tempuri.org/MethodName);

DotNetXmlHttp.Send(‘<?xml version=”1.0″ encoding=”utf-8″?>’ +
‘<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>&#8217; +
‘<soap:Body>’ +
‘<IsCustomerExist xmlns=”http://tempuri.org/”>&#8217; +
‘<customerID>’+CustomerID+'</customerID>’ +
‘</IsCustomerExist>’ +
‘</soap:Body>’ +
‘</soap:Envelope>’);

DotNetXmlDoc.load(DotNetXmlHttp.responseBody);

IF DotNetXmlHttp.status = 200 THEN BEGIN

DotNetXmlNodeList := DotNetXmlDoc.getElementsByTagName(‘soap:Body’);

DotNetXmlNode := DotNetXmlNodeList.item(0);

EVALUATE(Output,UPPERCASE(DotNetXmlNode.text));

END;

DotNetXmlHttp DotNet MSXML.XMLHTTPRequestClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

DotNetXmlDoc DotNet MSXML.DOMDocumentClass.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

DotNetXmlNodeList DotNet MSXML.IXMLDOMNodeList.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

DotNetXmlNode DotNet MSXML.IXMLDOMNode.’Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

Consume .NET WebService (Automation)

 

CREATE(AutXmlDoc,FALSE,TRUE);

CREATE(AutXmlHttp,FALSE,TRUE);

AutXmlHttp.open(‘POST’,’URL’,0); // If Username PWD then provide with comma separator else 0.

AutXmlHttp.SetRequestHeader(‘Host’,’Server Name’);

AutXmlHttp.SetRequestHeader(‘Content-Type’,’text/xml; charset=utf-8′);

AutXmlHttp.SetRequestHeader(‘Content-Length’,’Length’);

AutXmlHttp.SetRequestHeader(‘SOAPAction’,’http://tempuri.org/Method Name’);

AutXmlHttp.SetTimeouts(10000,10000,10000,0);

AutXmlHttp.Send(‘<?xml version=”1.0″ encoding=”utf-8″?>’ +
‘<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>’+
‘<soap:Body>’ +
‘<ValidateAddress xmlns=”http://tempuri.org/”>&#8217; +
‘<Address>’+Address+'</Address>’ +
‘<City>’+City+'</City>’ +
‘<State>’+State+'</State>’ +
‘<Zipcode>’+ZipCode+'</Zipcode>’ +
‘<Country>’+Country+'</Country>’ +
‘</ValidateAddress>’ +
‘</soap:Body>’ +
‘</soap:Envelope>’);

AutXmlDoc.load(AutXmlHttp.responseBody);

IF AutXmlHttp.status = 200 THEN BEGIN

AutXmlNodeList := AutXmlDoc.getElementsByTagName(‘soap:Body’); //Read XML Node

AutXmlNode := locautXmlNodeList.item(0);

EVALUATE(Output,UPPERCASE(locautXmlNode.text));

EXIT(Output);

END;

AutXmlHttp     Automation ‘Microsoft XML, v6.0’.ServerXMLHTTP60

AutXmlDoc      Automation ‘Microsoft XML, v6.0’.DOMDocument60

AutXmlNode    Automation ‘Microsoft XML, v6.0’.IXMLDOMNode

AutXmlNodeList Automation ‘Microsoft XML, v6.0’.IXMLDOMNodeList

Tempblob – How to Use

 

CLEAR(Tempblob);
Tempblob.INIT;
Tempblob.Blob.CREATEOUTSTREAM(Writestream);
XmlString.WRITE(writestream);
Tempblob.INSERT;
Tempblob.CALCFIELDS(Blob);
Tempblob.Blob.CREATEINSTREAM(Readstream);
XMLPORT.IMPORT(XMLPORT::”Name of Xmlport”,Readstream);

Variable – DataType
Tempblob – Record – Tempblob
XmlString – Bigtext
Writestream – OutStream
Readstream – InStream