i need help with a xml error, i’m trying to send a xml file to a CCV POS Engine
but i keep on getting this error (uploaded a jpg).
Exception: System.InvalidOperationException: The XML-document (2, 2) contains a error. —> System.InvalidOperationException: was not expected
if i dont add the xmlns attribute i get the same error.
It looks like you’re trying to create more than one root element. Everything after the ServiceRequest element needs to be a descendant node. Can you post the xml document this generates?
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using OPI_POS.Classes;
namespace OPI_POS.Classes
{
class TCPClient
{
private const string ServerAddress = "127.0.0.1";
private const int port = 4200; // eft-engine 4200
public TCPClient()
{
using (Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
// Adressing
IPHostEntry entry = Dns.GetHostEntry(ServerAddress);
IPAddress ipAddress = entry.AddressList[0];
IPEndPoint serverEndPoint = new IPEndPoint(ipAddress, port);
Debug.Print("Connecting to CCV Pos Engine " + serverEndPoint + ".");
clientSocket.Connect(serverEndPoint);
Debug.Print("Connected to CCV Pos Engine.");
//Sending
clientSocket.Send(Request.LoginRequest());
}
}
}
}
My Main
using System;
using System.Threading;
using Microsoft.SPOT;
using OPI_POS.Classes;
namespace OPI_POS
{
public class Program
{
public static void Main()
{
Thread mythread1 = new Thread(tcp);
Thread mythread2 = new Thread(server);
mythread2.Start();
mythread1.Start();
Thread.Sleep(Timeout.Infinite);
}
private static void tcp()
{
TCPClient tcp = new TCPClient();
}
private static void server()
{
TCPServer tcp = new TCPServer();
}
}
}
this is my requests class all the function keep givng the same error
using System;
using System.IO;
using System.Xml;
using System.Ext.Xml;
using Microsoft.SPOT;
namespace OPI_POS.Classes
{
public static class Request
{
private static string WorkstationId = "EmbeddedKiosk";
private static string time = DateTime.Now.ToString();
public static string SendRequest()
{
MemoryStream ms = new MemoryStream();
XmlWriter xmlwrite = XmlWriter.Create(ms);
xmlwrite.WriteRaw("\r\n");
xmlwrite.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
xmlwrite.WriteStartElement("CardServiceRequest");
xmlwrite.WriteAttributeString("WorkstationID", WorkstationId);
xmlwrite.WriteAttributeString("RequestID","1");
xmlwrite.WriteAttributeString("RequestType","CardPayment");
xmlwrite.WriteAttributeString("ApplicationID","{ApplicationID}");
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("POSData");
xmlwrite.WriteAttributeString("LanguageCode", "nl");
xmlwrite.WriteAttributeString("ApprovalCode", "{ApprovalCode}");
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("POSTimeStamp");
xmlwrite.WriteString(time);
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("ShiftNumber");
xmlwrite.WriteString("0");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("ClerkID");
xmlwrite.WriteString("{ClerkID}");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("PrinterStatus");
xmlwrite.WriteString("Unavailable");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("VoiceReferral");
xmlwrite.WriteString("{VoiceReferral}");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("MerchantReference");
xmlwrite.WriteString("{MerchantReference}");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("TotalAmount");
xmlwrite.WriteAttributeString("Currency", "EUR");
xmlwrite.WriteString("50");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteEndElement(); // End root
xmlwrite.Flush();
xmlwrite.Close();
//////// display the XML data ///////////
byte[] byteArray = ms.ToArray();
char[] cc = System.Text.UTF8Encoding.UTF8.GetChars(byteArray);
string str = new string(cc);
Debug.Print(str);
return byteArray.ToString();
}
public static byte [] CardServiceRequest()
{
MemoryStream ms = new MemoryStream();
XmlWriter xmlwrite = XmlWriter.Create(ms);
//xmlwrite.WriteRaw("\r\n\t");
xmlwrite.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
xmlwrite.WriteStartElement("CardServiceRequest");
xmlwrite.WriteAttributeString("WorkstationID", WorkstationId);
xmlwrite.WriteAttributeString("RequestID","1");
xmlwrite.WriteAttributeString("RequestType","CardPayment");
xmlwrite.WriteAttributeString("xmlns",null,"http://www.nrf-arts.org/IXRetail/namespace");
//xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("POSdata");
xmlwrite.WriteAttributeString("LanguageCode", "nl");
//xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("POSTimeStamp");
xmlwrite.WriteString(time);
xmlwrite.WriteEndElement();
//xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("ShiftNumber");
xmlwrite.WriteString("0");
xmlwrite.WriteEndElement();
//xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("PrinterStatus");
xmlwrite.WriteString("Unavailable");
xmlwrite.WriteEndElement();
//xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteEndElement();
//xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteStartElement("TotalAmount");
xmlwrite.WriteAttributeString("Currency", "EUR");
xmlwrite.WriteString("5.00");
xmlwrite.WriteEndElement();
//xmlwrite.WriteString("\r\n\t");
xmlwrite.WriteEndElement(); // End root
xmlwrite.Flush();
xmlwrite.Close();
//////// display the XML data ///////////
byte[] byteArray = ms.ToArray();
char[] cc = System.Text.UTF8Encoding.UTF8.GetChars(byteArray);
string str = new string(cc);
Debug.Print(str);
return ms.ToArray();
}
public static byte[] LoginRequest()
{
MemoryStream ms = new MemoryStream();
XmlWriter xmlwrite = XmlWriter.Create(ms);
xmlwrite.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
xmlwrite.WriteString("\r\t");
xmlwrite.WriteStartElement("ServiceRequest");
xmlwrite.WriteAttributeString("WorkstationID", WorkstationId);
xmlwrite.WriteAttributeString("RequestID", "1");
xmlwrite.WriteAttributeString("RequestType", "Login");
xmlwrite.WriteAttributeString("xmlns","http://www.nrf-arts.org/IXRetail/namespace");
xmlwrite.WriteString("\r\t");
xmlwrite.WriteStartElement("POSdata");
xmlwrite.WriteAttributeString("LanguageCode", "nl");
xmlwrite.WriteString("\r\t");
xmlwrite.WriteStartElement("POSTimeStamp");
xmlwrite.WriteString(time);
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\t");
xmlwrite.WriteStartElement("ShiftNumber");
xmlwrite.WriteString("0");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\t");
xmlwrite.WriteStartElement("PrinterStatus");
xmlwrite.WriteString("Unavailable");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\t");
xmlwrite.WriteEndElement();
xmlwrite.WriteString("\r\t");
xmlwrite.WriteEndElement(); // End root
xmlwrite.Flush();
byte[] byteArray = ms.ToArray();
xmlwrite.Close();
//////// display the XML data ///////////
char[] cc = System.Text.UTF8Encoding.UTF8.GetChars(byteArray);
string str = new string(cc);
Debug.Print(str);
return byteArray;
}
}
}
I’d like to try without “\r\t” text nodes: they’re actually sibling nodes on infoset and I am not sure that XML rendering engine is able to manage them.
i did try it without “\r\t” text nodes already, but still getting the same error, communicating with de engine with delphi on pc works fine, but migrating it in c# micro is a bit of a struggle.
@ Architect i dont have engine documentation only instructions for xml requests.