get orders via webapi

Posted By polychromenz Thu 26 Jun 2014
Add to Favorites0
Author Message
polychromenz
 Posted Wed 2 Jul 2014
Supreme Being

Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
And you'll need something like this to get that text into a datatable
Public Shared Function KartrisWebAPI_DataTableResult(pXMLResult As String) As DataTable

'Format is <?xml version="1.0" encoding="utf-16"?> <boolean>true</boolean>

Dim XMLDoc As New XmlDocument()

pXMLResult = pXMLResult.Replace("&lt;", "<")

pXMLResult = pXMLResult.Replace("&gt;", ">")

XMLDoc.LoadXml(pXMLResult)

Dim nodeList As XmlNodeList = XMLDoc.GetElementsByTagName("KartrisdataTable")

Dim i As Integer

Dim xmlData As String

For i = 0 To nodeList.Count - 1

xmlData = nodeList(i).InnerText

xmlData = xmlData.Replace("&lt;", "<")

xmlData = xmlData.Replace("&gt;", ">")

Next

Dim ds As New DataSet

Dim dt As DataTable

Dim sr As New StringReader(pXMLResult)

ds.ReadXml(sr)

dt = ds.Tables(0)

Return dt

End Function

Wed 2 Jul 2014 by polychromenz
polychromenz
 Posted Wed 2 Jul 2014
Supreme Being

Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
Here are the new methods added to KartrisWebHelperBLL i'll post that later when it has datasets added

Public Shared Function Serialize(ByVal strObject As Object) As String
Dim strType As String = strObject.GetType.ToString.ToLower
Debug.Print(strType)
If strType = "system.data.datatable" Then
Return SerializeTableToString(strObject)
Else
Dim oXS As XmlSerializer = New XmlSerializer(strObject.GetType)
Dim oStrW As New StringWriter()
'Serialize the object into an XML string

oXS.Serialize(oStrW, strObject)
Serialize = oStrW.ToString()
oStrW.Close()

End If
End Function


Public Shared Function SerializeTableToString(ptable As DataTable) As String
If ptable Is Nothing Then
Return Nothing
Else
Using sw = New StringWriter()
Using tw = New XmlTextWriter(sw)
' Must set name for serialization to succeed.
ptable.TableName = "results"
tw.Formatting = Formatting.Indented

tw.WriteStartDocument()

tw.WriteStartElement("KartrisdataTable")
DirectCast(ptable, Serialization.IXmlSerializable).WriteXml(tw)

tw.WriteEndElement()
tw.WriteEndDocument()

tw.Flush()
tw.Close()
sw.Flush()

Return sw.ToString()
End Using
End Using
End If
End Function

polychromenz
 Posted Wed 2 Jul 2014
Supreme Being

Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
Finally got some time to come back to this today

There are several issues here, part of the problem is that there is no real method in OrdersBLL that returns orders. We could try GetOrderByID or we can add our own method to get the orders rows.

The problem with this is that some columns contain whole html documents containing dtds and trying to deserialize these is a PITA

Also the WebAPI calls the payment.serialize method (not sure why this hasn't been moved to a more generic location as everything else in Kartis is SO tidy it makes me want to hide my code)

The payments.serialize method is very generic and doesn't know if it is serializing a datatable and so it doesn't know that it needs to add a table name to work.

I have worked around these issues by

added a new helperclass OrdersHelperBLL that has a method that only selects the columns I want. I guess that could be updated to let the dev pass in the SQL but that probably not a great idea Wink

changed the webapi to call my own serialize method (in my updated katriswebhelperBLL that checks if it is working with a datatable and acts accordingly.

now I get a datatable back that I can consume and work with, i'll update my code to handle datasets to so that I can get the headers and lines but I wanted to post a quick update.

So you would need to change KartisWebAPI.Execute as follows (near the end)

If m IsNot Nothing Then

'Call the method and serialize the results

strOutput = KartrisWebHelperBLL.Serialize(m.Invoke(obj, Params))

Else


polychromenz
 Posted Thu 26 Jun 2014
Supreme Being

Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)Supreme Being - (6,488 reputation)

Group: Forum Members
Last Active: Thu 21 Sep 2017
Posts: 13, Visits: 179
Struggling to get orders via the web api. What method should I call. If I try to add my own that returns a datatable then the resulting XML is unusable. Am I missing anything obvious?

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top