WebAPI Examples

Posted By Boxson Tue 5 Nov 2013
Add to Favorites0
Author Message
Boxson
 Posted Tue 5 Nov 2013
Supreme Being

Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)

Group: Forum Members
Last Active: Thu 12 Dec 2013
Posts: 14, Visits: 70
Hi,

i'm still working through the webAPI to connect a base system to Kartris.

I'm stuck with methods which ask for a parameter - type "dataTable".

As an example the method CategoriesBLL._AddCategory ask's for a dataTable as first parameter:

Public Shared Function _AddCategory(ByVal ptblElements As DataTable, ByVal pParentsList As String, _       ByRef pCategoryID As Integer, ByVal pLive As Boolean, ByVal pProductDisplayType As Char, _       ByVal pSubCatDisplayType As Char, ByVal pOrderProductsBy As String, _       ByVal pProductsSortDirection As Char, ByVal pOrderSubcatBy As String, _       ByVal pSubcatSortDirection As Char, ByVal pCustomerGroupID As Integer, ByRef strMsg As String) As Boolean

How does the strParameterXML String have to look like? Doesn't matter what i send, i'll get an XML Error (1,1).

Method's which does not have a dataTable as a parameter ca be called without any problem.

any help apreciated! Is there any source for examples? The one that's delivered with kartris doesn't handle dataTable parameters.
Paul
 Posted Tue 5 Nov 2013
große Käse

große Käse - (522,682 reputation)große Käse - (522,682 reputation)große Käse - (522,682 reputation)große Käse - (522,682 reputation)große Käse - (522,682 reputation)große Käse - (522,682 reputation)große Käse - (522,682 reputation)große Käse - (522,682 reputation)große Käse - (522,682 reputation)

Group: Administrators
Last Active: Tue 10 Sep 2024
Posts: 807, Visits: 2,748
Some data types such as dataTable are serializable, so they can be converted to XML and output from ASP.NET in string format. If the same XML is input, it can be turned back into the object. This is ASP.NET functionality rather than Kartris specific.

So in order to find the format to input XML to the Kartris BLL, the easiest way is to output XML of a dataTable from Kartris or .NET in general.

There is more info on serialization here:

http://msdn.microsoft.com/en-us/library/vstudio/ms233843.aspx

If the data you're trying to input to the Kartris web API is coming from another .NET application, I think it should just be a case of serializing the dataTable from that to XML and it should be in the correct format.

If outputting from another system, you'd have to manually match the XML format I think and write something to turn your data into the correct XML format for a dataTable.


--
If my post solves your issue, can you 'Mark as Answer' so it's easier for other users to find in future.

If you would like to be informed of new features, new releases, developments and occasional special bonuses, please sign up to our mailing list: http://bit.ly/19sKMZb
Boxson
 Posted Tue 5 Nov 2013
Supreme Being

Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)

Group: Forum Members
Last Active: Thu 12 Dec 2013
Posts: 14, Visits: 70
I've tried to serialisze a dataTable to xml and send the xml-string. This doesn't work.
The structure, the webAPI wants the parameters to be, is not clear to me. The following shows the structure of strParametersXML within the example in "Protected/"-folder:

<KartrisWebAPI>
<Parameters>
<Parameter Name="_LE_LanguageID" Type="short">
<Value>1</Value>
</Parameter>
</Parameters>
</KartrisWebAPI>

This is ok and clear and works.

But how should a dataTable be implemented here. Is the DataTable on the level of a Parameter or is the DataTable the value of a parameter?
Does the DataTable need to be within "<Value>" Tags or does it have it's own?
Medz Marked As Answer
 Posted Tue 5 Nov 2013
Kartris Expert

Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)Kartris Expert - (67,624 reputation)

Group: Administrators
Last Active: Tue 3 Dec 2013
Posts: 99, Visits: 1,400
An update to the Web API code had been pushed to improve method parameter type handling. Please download the latest patch to get the latest fixes and improvements ->

(updated App_Code/KartrisWebAPI.vb)
https://www.codeplex.com/Download?ProjectName=kartris&DownloadId=754964



The full xml string of the serialized datatable has to be inside the value tag. Because its a full XML markup, you need to enclose it inside CDATA section.

Example of a full strParametersXML string parameter for _AddCategory method ->

<?xml version="1.0" encoding="utf-8" ?><KartrisWebAPI><Parameters><Parameter Name="ptblElements" Type="DataTable"><Value><![CDATA[ <?xml version="1.0" encoding="utf-16"?>  <DataTable>    <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">      <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="tblCategoryLanguageElements" msdata:UseCurrentLocale="true">        <xs:complexType>          <xs:choice minOccurs="0" maxOccurs="unbounded">            <xs:element name="tblCategoryLanguageElements">              <xs:complexType>                <xs:sequence>                  <xs:element name="_LE_LanguageID" type="xs:string" minOccurs="0" />                  <xs:element name="_LE_FieldID" type="xs:string" minOccurs="0" />                  <xs:element name="_LE_Value" type="xs:string" minOccurs="0" />                </xs:sequence>              </xs:complexType>            </xs:element>          </xs:choice>        </xs:complexType>      </xs:element>    </xs:schema>    <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">      <DocumentElement>        <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements1" msdata:rowOrder="0" diffgr:hasChanges="inserted">          <_LE_LanguageID>1</_LE_LanguageID>          <_LE_FieldID>1</_LE_FieldID>          <_LE_Value>CategoryNameValue</_LE_Value>        </tblCategoryLanguageElements>        <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements2" msdata:rowOrder="1" diffgr:hasChanges="inserted">          <_LE_LanguageID>1</_LE_LanguageID>          <_LE_FieldID>2</_LE_FieldID>          <_LE_Value>CategoryDescriptionValue</_LE_Value>        </tblCategoryLanguageElements>        <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements3" msdata:rowOrder="2" diffgr:hasChanges="inserted">          <_LE_LanguageID>1</_LE_LanguageID>          <_LE_FieldID>3</_LE_FieldID>          <_LE_Value />        </tblCategoryLanguageElements>        <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements4" msdata:rowOrder="3" diffgr:hasChanges="inserted">          <_LE_LanguageID>1</_LE_LanguageID>          <_LE_FieldID>4</_LE_FieldID>          <_LE_Value />        </tblCategoryLanguageElements>        <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements5" msdata:rowOrder="4" diffgr:hasChanges="inserted">          <_LE_LanguageID>1</_LE_LanguageID>          <_LE_FieldID>5</_LE_FieldID>          <_LE_Value />        </tblCategoryLanguageElements>        <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements6" msdata:rowOrder="5" diffgr:hasChanges="inserted">          <_LE_LanguageID>1</_LE_LanguageID>          <_LE_FieldID>8</_LE_FieldID>          <_LE_Value />        </tblCategoryLanguageElements>      </DocumentElement>    </diffgr:diffgram>  </DataTable> ]]> </Value></Parameter><Parameter Name="pParentsList" Type="String"><Value></Value></Parameter><Parameter Name="pCategoryID" Type="Integer"><Value>0</Value></Parameter><Parameter Name="pLive" Type="Boolean"><Value>True</Value></Parameter><Parameter Name="pProductDisplayType" Type="Char"><Value>d</Value></Parameter><Parameter Name="pSubCatDisplayType" Type="Char"><Value>d</Value></Parameter><Parameter Name="pOrderProductsBy" Type="String"><Value>d</Value></Parameter><Parameter Name="pProductsSortDirection" Type="Char"><Value>A</Value></Parameter><Parameter Name="pOrderSubcatBy" Type="String"><Value>d</Value></Parameter><Parameter Name="pSubcatSortDirection" Type="Char"><Value>A</Value></Parameter><Parameter Name="pCustomerGroupID" Type="Integer"><Value>0</Value></Parameter><Parameter Name="strMsg" Type="String"><Value></Value></Parameter></Parameters></KartrisWebAPI>
Boxson
 Posted Wed 6 Nov 2013
Supreme Being

Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)

Group: Forum Members
Last Active: Thu 12 Dec 2013
Posts: 14, Visits: 70
Thanks for your help! I've loaded the patch and changed the vb at the server. After that i used your code and sent this inside a "<Value></Value>" to the WebAPI. The WebAPI returns a deserialisation error:

I checked the action with SoapUI. The Result is as follows:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">aBigGrineserializationFailed</faultcode><faultstring xml:lang="de-DE">Der Formatierer hat beim Deserialisieren der Nachricht eine Ausnahme ausgelöst: Fehler beim Deserialisieren des Textkörpers der Anforderungsnachricht für Vorgang "Execute". Es wurde das Endelement "strParametersXML" aus Namespace "http://tempuri.org/" erwartet. Gefunden wurde "Element "KartrisWebAPI" aus Namespace "http://tempuri.org/"". Zeile 6, Position 28.</faultstring></s:Fault></s:Body></s:Envelope>


the Request i sent is:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<Execute xmlns="http://tempuri.org/">
<strMethod>CategoriesBLL._AddCategory</strMethod>
<strParametersXML>
<KartrisWebAPI>
<Parameters>
<Parameter Name="ptblElements" Type="DataTable">
<Value><![CDATA[<?xml version="1.0" encoding="utf-16"?> <DataTable> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="tblCategoryLanguageElements" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="tblCategoryLanguageElements"> <xs:complexType> <xs:sequence> <xs:element name="_LE_LanguageID" type="xs:string" minOccurs="0" /> <xs:element name="_LE_FieldID" type="xs:string" minOccurs="0" /> <xs:element name="_LE_Value" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> <DocumentElement> <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements1" msdata:rowOrder="0" diffgr:hasChanges="inserted"> <_LE_LanguageID>1</_LE_LanguageID> <_LE_FieldID>1</_LE_FieldID> <_LE_Value>CategoryNameValue</_LE_Value> </tblCategoryLanguageElements> <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements2" msdata:rowOrder="1" diffgr:hasChanges="inserted"> <_LE_LanguageID>1</_LE_LanguageID> <_LE_FieldID>2</_LE_FieldID> <_LE_Value>CategoryDescriptionValue</_LE_Value> </tblCategoryLanguageElements> <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements3" msdata:rowOrder="2" diffgr:hasChanges="inserted"> <_LE_LanguageID>1</_LE_LanguageID> <_LE_FieldID>3</_LE_FieldID> <_LE_Value /> </tblCategoryLanguageElements> <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements4" msdata:rowOrder="3" diffgr:hasChanges="inserted"> <_LE_LanguageID>1</_LE_LanguageID> <_LE_FieldID>4</_LE_FieldID> <_LE_Value /> </tblCategoryLanguageElements> <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements5" msdata:rowOrder="4" diffgr:hasChanges="inserted"> <_LE_LanguageID>1</_LE_LanguageID> <_LE_FieldID>5</_LE_FieldID> <_LE_Value /> </tblCategoryLanguageElements> <tblCategoryLanguageElements diffgr:id="tblCategoryLanguageElements6" msdata:rowOrder="5" diffgr:hasChanges="inserted"> <_LE_LanguageID>1</_LE_LanguageID> <_LE_FieldID>8</_LE_FieldID> <_LE_Value /> </tblCategoryLanguageElements> </DocumentElement> </diffgr:diffgram> </DataTable>]]></Value>
</Parameter>
<Parameter Name="pParentsList" Type="String">
<Value/>
</Parameter>
<Parameter Name="pCategoryID" Type="Integer">
<Value>0</Value>
</Parameter>
<Parameter Name="pLive" Type="Boolean">
<Value>True</Value>
</Parameter>
<Parameter Name="pProductDisplayType" Type="Char">
<Value>d</Value>
</Parameter>
<Parameter Name="pSubCatDisplayType" Type="Char">
<Value>d</Value>
</Parameter>
<Parameter Name="pOrderProductsBy" Type="String">
<Value>d</Value>
</Parameter>
<Parameter Name="pProductsSortDirection" Type="Char">
<Value>A</Value>
</Parameter>
<Parameter Name="pOrderSubcatBy" Type="String">
<Value>d</Value>
</Parameter>
<Parameter Name="pSubcatSortDirection" Type="Char">
<Value>A</Value>
</Parameter>
<Parameter Name="pCustomerGroupID" Type="Integer">
<Value>0</Value>
</Parameter>
<Parameter Name="strMsg" Type="String">
<Value/>
</Parameter>
</Parameters>
</KartrisWebAPI>
</strParametersXML>
</Execute>
</s:Body>
</s:Envelope>
Wed 6 Nov 2013 by Boxson
Boxson Marked As Answer
 Posted Wed 6 Nov 2013
Supreme Being

Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)Supreme Being - (10,988 reputation)

Group: Forum Members
Last Active: Thu 12 Dec 2013
Posts: 14, Visits: 70
Found the solution. I had to replace all occurencies of "<" and ">" with the encoded equivalents. Now it's workin.

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top