Hi,
I need to call a web service and read the XML.
I can call the web service, receive the reply but when I try to read the values, for example put the values on a message, I always get the error “A DotNet variable has not been instantiated. Attempting to call System.Xml.XmlNode.Value in CodeUnit CallSLBWS: GetSIPUsers”
This is my code
PROCEDURE GetSIPUsers@1000000001();
VAR
I@1000000021 : Integer;
XMLRequestDoc@1000000001 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
XMLResponseDoc@1000000002 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
XMLProsInstr@1000000003 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlProcessingInstruction";
XMLElement1@1000000006 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlElement";
XMLElement2@1000000005 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlElement";
XMLElement3@1000000004 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlElement";
HttpWebRequest@1000000024 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest";
URL@1000000025 : Text;
MemoryStream@1000000026 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream";
HttpWebResponse@1000000027 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebResponse";
HttpWebException@1000000030 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebException";
CaminhoXML@1000000031 : Text;
XMLNodeResponse@1000000033 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
XMLNodeList@1000000032 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNodeList";
FileName@1000000035 : Text;
PurchSetup@1000000036 : Record 312;
Codes@1000000028 : Record 50008;
XMLNodeID@1000000000 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
XMLNodeUserName@1000000009 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
XMLNodeFullName@1000000010 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
ID@1000000011 : Integer;
BEGIN
PurchSetup.GET;
PurchSetup.TESTFIELD("SIP URL");
XMLRequestDoc := XMLRequestDoc.XmlDocument;
XMLResponseDoc := XMLResponseDoc.XmlDocument;
XMLProsInstr := XMLRequestDoc.CreateProcessingInstruction('xml','version="1.0" encoding="utf-8"');
XMLRequestDoc.AppendChild(XMLProsInstr);
XMLElement1 := XMLRequestDoc.CreateElement('soap','Envelope','http://schemas.xmlsoap.org/soap/envelope/');
XMLElement1.SetAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
XMLElement1.SetAttribute('xmlns:xsd','http://www.w3.org/2001/XMLSchema');
XMLElement2 := XMLRequestDoc.CreateElement('soap','Body', 'http://schemas.xmlsoap.org/soap/envelope/');
XMLElement3 := XMLRequestDoc.CreateElement('ListaUtilizadores');
XMLElement3.SetAttribute('xmlns',STRSUBSTNO('http://www.slbenfica.pt/'));
XMLElement2.AppendChild(XMLElement3);
XMLElement1.AppendChild(XMLElement2);
XMLRequestDoc.AppendChild(XMLElement1);
FileName := 'GetUsers_' + FORMAT(CURRENTDATETIME,0, '<Year4><Month,2><Day,2>_<Hours24,2><Minutes,2><Seconds,2>') + '_' + DELSTR(USERID, 1, STRLEN('BENFICA/'));
//XMLRequestDoc.Save(PurchSetup."SIP WS Logs" + FileName + '_Request.xml');
/////////////////////////
HttpWebRequest := HttpWebRequest.Create(PurchSetup."SIP URL");
HttpWebRequest.Timeout := 30000;
// HttpWebRequest.UseDefaultCredentials(TRUE)
HttpWebRequest.Method := 'POST';
HttpWebRequest.ContentType := 'text/xml; charset=utf-8';
HttpWebRequest.Accept := 'text/xml';
//HttpWebRequest.Headers.Add('SOAPAction','LoadTransaction');
MemoryStream := HttpWebRequest.GetRequestStream;
XMLRequestDoc.Save(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;
HttpWebResponse := HttpWebRequest.GetResponse;
MemoryStream := HttpWebResponse.GetResponseStream;
XMLResponseDoc := XMLResponseDoc.XmlDocument;
XMLResponseDoc.Load(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;
//XMLResponseDoc.Save(PurchSetup."SIP WS Logs" + FileName + '_Response.xml');
XMLNodeList := XMLResponseDoc.GetElementsByTagName('Utilizador');
FOR I := 0 TO XMLNodeList.Count - 1 DO BEGIN
XMLNodeID := XMLNodeList.Item(I).SelectSingleNode('Id/text()');
XMLNodeUserName := XMLNodeList.Item(I).SelectSingleNode('Username/text()');
XMLNodeFullName := XMLNodeList.Item(I).SelectSingleNode('FullName/text()');
MESSAGE('%1 - %2 - %3', FORMAT(XMLNodeID.Value), FORMAT(XMLNodeUserName.Value), FORMAT(XMLNodeFullName.Value));
END;
END;
Below is the XML file that I get
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ListaUtilizadoresResponse xmlns="http://www.slbenfica.pt/">
<ListaUtilizadoresResult>
<Utilizador>
<Id>2</Id>
<Username>admin</Username>
<FullName>Administrador </FullName>
</Utilizador>
<Utilizador>
<Id>193</Id>
<Username>argomes</Username>
<FullName>Alberto Rafael Gomes</FullName>
</Utilizador>
</ListaUtilizadoresResult>
</ListaUtilizadoresResponse>
</soap:Body>
</soap:Envelope>
Any sugestion?
thanks in advance,
NS
I need to call a web service and read the XML.
I can call the web service, receive the reply but when I try to read the values, for example put the values on a message, I always get the error “A DotNet variable has not been instantiated. Attempting to call System.Xml.XmlNode.Value in CodeUnit CallSLBWS: GetSIPUsers”
This is my code
PROCEDURE GetSIPUsers@1000000001();
VAR
I@1000000021 : Integer;
XMLRequestDoc@1000000001 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
XMLResponseDoc@1000000002 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
XMLProsInstr@1000000003 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlProcessingInstruction";
XMLElement1@1000000006 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlElement";
XMLElement2@1000000005 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlElement";
XMLElement3@1000000004 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlElement";
HttpWebRequest@1000000024 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest";
URL@1000000025 : Text;
MemoryStream@1000000026 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream";
HttpWebResponse@1000000027 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebResponse";
HttpWebException@1000000030 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebException";
CaminhoXML@1000000031 : Text;
XMLNodeResponse@1000000033 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
XMLNodeList@1000000032 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNodeList";
FileName@1000000035 : Text;
PurchSetup@1000000036 : Record 312;
Codes@1000000028 : Record 50008;
XMLNodeID@1000000000 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
XMLNodeUserName@1000000009 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
XMLNodeFullName@1000000010 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";
ID@1000000011 : Integer;
BEGIN
PurchSetup.GET;
PurchSetup.TESTFIELD("SIP URL");
XMLRequestDoc := XMLRequestDoc.XmlDocument;
XMLResponseDoc := XMLResponseDoc.XmlDocument;
XMLProsInstr := XMLRequestDoc.CreateProcessingInstruction('xml','version="1.0" encoding="utf-8"');
XMLRequestDoc.AppendChild(XMLProsInstr);
XMLElement1 := XMLRequestDoc.CreateElement('soap','Envelope','http://schemas.xmlsoap.org/soap/envelope/');
XMLElement1.SetAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
XMLElement1.SetAttribute('xmlns:xsd','http://www.w3.org/2001/XMLSchema');
XMLElement2 := XMLRequestDoc.CreateElement('soap','Body', 'http://schemas.xmlsoap.org/soap/envelope/');
XMLElement3 := XMLRequestDoc.CreateElement('ListaUtilizadores');
XMLElement3.SetAttribute('xmlns',STRSUBSTNO('http://www.slbenfica.pt/'));
XMLElement2.AppendChild(XMLElement3);
XMLElement1.AppendChild(XMLElement2);
XMLRequestDoc.AppendChild(XMLElement1);
FileName := 'GetUsers_' + FORMAT(CURRENTDATETIME,0, '<Year4><Month,2><Day,2>_<Hours24,2><Minutes,2><Seconds,2>') + '_' + DELSTR(USERID, 1, STRLEN('BENFICA/'));
//XMLRequestDoc.Save(PurchSetup."SIP WS Logs" + FileName + '_Request.xml');
/////////////////////////
HttpWebRequest := HttpWebRequest.Create(PurchSetup."SIP URL");
HttpWebRequest.Timeout := 30000;
// HttpWebRequest.UseDefaultCredentials(TRUE)
HttpWebRequest.Method := 'POST';
HttpWebRequest.ContentType := 'text/xml; charset=utf-8';
HttpWebRequest.Accept := 'text/xml';
//HttpWebRequest.Headers.Add('SOAPAction','LoadTransaction');
MemoryStream := HttpWebRequest.GetRequestStream;
XMLRequestDoc.Save(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;
HttpWebResponse := HttpWebRequest.GetResponse;
MemoryStream := HttpWebResponse.GetResponseStream;
XMLResponseDoc := XMLResponseDoc.XmlDocument;
XMLResponseDoc.Load(MemoryStream);
MemoryStream.Flush;
MemoryStream.Close;
//XMLResponseDoc.Save(PurchSetup."SIP WS Logs" + FileName + '_Response.xml');
XMLNodeList := XMLResponseDoc.GetElementsByTagName('Utilizador');
FOR I := 0 TO XMLNodeList.Count - 1 DO BEGIN
XMLNodeID := XMLNodeList.Item(I).SelectSingleNode('Id/text()');
XMLNodeUserName := XMLNodeList.Item(I).SelectSingleNode('Username/text()');
XMLNodeFullName := XMLNodeList.Item(I).SelectSingleNode('FullName/text()');
MESSAGE('%1 - %2 - %3', FORMAT(XMLNodeID.Value), FORMAT(XMLNodeUserName.Value), FORMAT(XMLNodeFullName.Value));
END;
END;
Below is the XML file that I get
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ListaUtilizadoresResponse xmlns="http://www.slbenfica.pt/">
<ListaUtilizadoresResult>
<Utilizador>
<Id>2</Id>
<Username>admin</Username>
<FullName>Administrador </FullName>
</Utilizador>
<Utilizador>
<Id>193</Id>
<Username>argomes</Username>
<FullName>Alberto Rafael Gomes</FullName>
</Utilizador>
</ListaUtilizadoresResult>
</ListaUtilizadoresResponse>
</soap:Body>
</soap:Envelope>
Any sugestion?
thanks in advance,
NS