38 posts / 0 new
Last post
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:
AppMancer

This is the thread to ask questions and see demos of the AppMancer library for MoSync. See www.appmancer.com for more details and downloads.

AppMancer is a collection of open-source C++ libraries which extend and enhance MoSync.

AMDownload is an advanced HTTP/S library which takes the heavy lifting out of downloads. It includes caching, authentication, request queueing, HTTP redirection (301 and 302) and servers which don't provide a content-length header.

AMUtil is a free library of utility functions, some ports and some original, including snprintf, sscanf, Base64, MD5 and URLEncode.

AMUI is an advanced UI Widget system which extends MoSync's MAUI library with new widget functions, new widgets, and integrated NativeUI. Applications built with AMUI can use Android and iOS native UI components with one additional line of code. Also includes XML data binding of widgets.

AMXML is an XML DOM parser with XPath support.

AMJSON is a full implementation of JSON, with a navigator.

AMSOAP provides a simple interface to AMXML and AMDownload to make and understand SOAP requests.

+ many more libraries and enhancements to come.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
James Agada
James.Agada's picture
Offline
Joined: 22 Oct 2011
Posts:

Working examples and some documentation needed!

James Agada
James.Agada's picture
Offline
Joined: 22 Oct 2011
Posts:

Still no documentation and no working examples!

Christopher Erasmus
Cyro's picture
Offline
Mobile Conjurer
Joined: 21 Nov 2011
Posts:

Hi Sam, I've trying out the AppMancer lib specifically the AMSoap.lib and I've been over to the wiki to get some indication as to how it works. If you could shed some light on how to start the whole process. If not, am I correct in saying that I could the DownloadManager to get post Soap Requests and get Responses? I'm currently trying to get my company to purchase AppMancer for the support, just need to justify it. Hope to hear from you soon.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi Christopher. The wiki is very new and I'll be writing a lot more into it over the weekend, but its my mum's birthday today, so I'm going to see her first :-)

The AMSoap library helps make it easy to make SOAP request. You create a new SoapRequest and give it a service end point, soap method and action (plus namespaces or any other parameters you need to add to make the request). The SoapRequest will format the Soap call and download the response. You specify the Xpath to the response data you want, and once the request has been fulfilled, you can call the getResponse() method to get an XmlNode* back.

Internally, the SoapRequest class makes a DownloadRequest and uses the DownloadManager to perform the download.

You can the use the XmlNode with XmlDataBinding and write the contents directly to the UI.

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Hi Sam,
I also tried your extension, glad to see how it makes better Mosync and give me lots of useful stuff.
I have some(actually, lots of) questions:
Is there an opportunity to use Appmancer and Mosync in Visual Studio 2010 Express? I have tried, but get en error message at compile. (Or,I should just recompile appmancer source in VS, and It will work? )
Another problem related to XmlRepeater, My app connects to a SOAP service, get some data, and I would like to see a result list in UI, the listener is built in the screen, in constructor I define the xmlayout for repeater, It is added to the repeater, and I add the repeater into the mLayout. In the resultComplete function I bind the xmlDoc into the repeater, but after there is a big black hole at the screen...
The SOAP is working flawless, XmlDoc has the proper data in the function. Did I forget something like draw or repaint?
Is there an opportunity to bind Vectors of domain classes or SimpleLists into the repeater directly?
I use MS WCF service at the moment, and the SOAP response of that service not contains values, values travels in XmlNode's innertext parts, but binding in Labels watch only the getValue value, currently I move all of the XmlNodes' Innertext values into Value properties before display. Is there a nicer way to get it work?
Thanks for your answer!

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Wow Teddy - you've gone to town! I get quite excited when I see people try things like this. I'll try to address your questions in order.

1. Visual Studio. I've not really tried MoSync development in VS for about 3 years. I used to use it all the time, in the days before MoSync had a proper IDE. Integration with VS2005 was quite good, but I used their old build tool for all building. I've no idea if the debugger will work for instance, or indeed if VS supports all the C++ commands I've used. One springs to mind instantly, which is defining an array length from a variable like this:

void allocArray(int len)
{
  char a[len];
}

Which works fine with GCC, but I'm not sure if it is supported with MSC++.  I'm kind of with you, I love Visual Studio, but I made the break and jumped to Eclipse. There are still VS features I wish it supported.  Anyway, in theory you can configure MoSync to work with VS 2010, there is a guide somewhere.  If you can get MoSync projects building and debugging in it, then I think you may be able to use AppMancer with it as well, but watch out for examples like the one above.  I've certainly never tested AppMancer with a different compiler.

2.  XmlDataBinding.  Are you using AMXml?  I think you must be, but XmlDataBinding only working with AMXml XmlNode classes.  The XmlRepeater is a widget itself, so you have to add that XmlRepeater to the screen or the layout or whatever it is that you want to populate.  The second option is that the XPath implementation isn't a complete implementation.  Its a very pragmatic approach, and may not work with some complex XPaths or aggregate functions.  The other idea I've got is that your SOAP data may include a SOAP namespace,  If so, you may have to include the namespace name in the XPaths you want, like "/ns1:header/ns1:title" for instance.  Try a little debug with the XML you've got to test the XPath.  Something like:

lprintfn("I've got %d nodes", mySoap->selectNodes("/ns1:header/ns1:title").size());

And see how many nodes that XPath has selected.  If you need to, post some example data and I'll build a quick example of using XmlDataBinder with it.

On another note, XmlRepeater is about to change shortly.  Currently it is limited to creating a ListBox with a widget in each row.  I'm going to change this so that the XmlRepeater will add widgets to any other widget, which will give you a lot more flexibility.

3.  Binding other data.  Yeah, Vectors or SimpleList (or any AMCollections IEnumerable) would be cool, but I'm restricted by C++ here I think.  If anyone knows a way around this problem, I'd love to hear it, and I'll implement it into AppMancer.

The problem is this:  You can do it in C# (for instance) because the language and the CLR supports reflection.  I can take an object I've never seen before, and find what property and methods it supports.  I can then call those methods, or get those properties.  I don't need any knowledge of the object at build time.  ASAIK, C++ doesn't support this at all.  So I can do it with C# because I can have a process like this:

XmlDataBinder has a widget which wants data binding.  It isn't bound to an XPath, but the the 'name' property of an object.  Here is a SimpleList of objects.  I'll take the next one.  Do you have a property called name?  You do?  Cool, can I have the value, so I can set the setText property of the widget.  In C++, even if I can examine the object, I can't eval a call to unknownObject->getName().  The call the method has to resolve at compile time.

Using Lua may be the answer to this.  I'll try to speak to Micke about it.  Watch this space.

4.  Binding to inner text.  I think I need to see some example data for this. I've just checked the XmlRepeater source code, and it already tries to take the InnerText value of the node, which should work just like the .NET XmlNode.InnerText() method.

widget->setText(valueNode->getInnerText());

I think I need to see some data if you can share it.

Keep up the good work!  I'm adding a lot of documentation all the time to the wiki at https://appmancer.repositoryhosting.com/trac/appmancer_appmancer30/wiki

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Thank you for your reply, I have only answer quickly for the data bindings. I use your appmancer template project for start, AMXml, AMXml::XMLNode, and the other good stuff. The selectnode route strings was good, I had managed to write the name of objects into LOG.

ForumScreen inherited from BaseScreen, the constructor is:

ForumScreen::ForumScreen()
{
	addHeader("Topic List");

	/*define the center layout*/
	xmlRepeater=new XMLRepeater(0,0,100,100,NULL);
	xmlRepeater->setAllowResize(Widget::ALLOW_RESIZE_BOTH);

	//create template widget for forum topics' rows
	xmlRowLayout = new StackLayout(0,0,ScreenSize::width(),30,NULL,StackLayout::SL_HORIZONTAL);
	mLayout->add(xmlRepeater);

	forumTitle = createLabel("Topic X");
	forumTitle->setHeight(30);
	forumTitle->setBackgroundColor(GREEN);
	forumTitle->setAllowResize(Widget::ALLOW_RESIZE_X_ONLY);
	forumTitle->setDataXPath("a:Name");
	xmlRowLayout->add(forumTitle);

	Button* showButton = createButton("Show");
	showButton->setAllowResize(Button::ALLOW_RESIZE_Y_ONLY);
	showButton->setWidth(60);
	xmlRowLayout->add(showButton);
	/**/
	xmlRepeater->add(xmlRowLayout);

	/* We don't want to add any other new widgets, so just show the soft keys at the bottom */
	addSoftKeys();

	//SOAP call
	ForumServiceClient::loadTopicList(forumid,this);
}

Binding the repeater in another function:

xmlRepeater->dataBind(xmlDoc->rootNode,"/s:Envelope/s:Body/GetTopicListResponse/GetTopicListResult/a:Topic");
xmlRepeater->requestRepaint();

I have to call repaint for changing screen state(the template row in repeater only disappears, but after shows only black)
The xml response from service is(value.innerText() binding should be working with that):

<?xml version = "1.0" ?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <GetTopicListResponse xmlns="http://tempuri.org/">
      <GetTopicListResult xmlns:a="http://schemas.datacontract.org/2004/07/Forum.WcfService.DataContracts"
                           xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Topic>
          <a:CreatedAt>2012-01-03T18:48:54.877</a:CreatedAt>
          <a:CreatedByName>admin</a:CreatedByName>
          <a:Description i:nil="true" />
          <a:ForumId>0</a:ForumId>
          <a:Id>88</a:Id>
          <a:Name>Topic 1</a:Name>
        </a:Topic>
  </GetTopicListResult>
    </GetTopicListResponse>
  </s:Body>
</s:Envelope>

I am currently trying to figure out what is the problem, I think I find an issue in your code: XMLReader class has a declaration issue in the XMLNode.h, and compiler cant find XMLReader's definition. I have included the XMLReader.h, and using namespace AMXml, but there is a compiler error with that simple code: Type aggregate `AMXml::XMLReader xr' has incomplete type and cannot be defined

AMXml::XMLReader xr;
XmlDocument* testXmlDoc = xr.parseXML(xmlStr);
Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

PS: The issue is not related to XMLRepeater, It just raised when I tryed to parse a test xml string to get the repeater work in constructor.
I also fight with VS2010, currently it doesn't like the AMUtil.lib:
error LNK1107: invalid or corrupt file: cannot read at 0x27DEC E:\MoSync\lib\pipe\AMUtil.lib
I have changed the char[length] parts in my code, and investigating the amutil source.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Morning,

This code below is based on HomeScreen.cpp from the Starter Application.  I think I've found the trouble with the repeater.

#include "HomeScreen.h"

/* We always want to include std.h, as it has a lot of global settings in it */
#include "../std.h"

/* There are some useful factory methods in UIHelper which make building widgets a bit easier */
#include "../UIHelper.h"

/* And we need access to the moblet if the user wants to quit */
#include <MAUtil/Moblet.h>
#include <AMUI/XMLRepeater.h>
#include <AMUI/Colours.h>
#include "../Utilities/XmlToData.h"
#include "MAHeaders.h"
/* This is the code for the constructor */
HomeScreen::HomeScreen()
{
	mTitle->setCaption("Topic List");

	/*define the center layout*/
	XMLRepeater* xmlRepeater = new XMLRepeater(0,0,100,100,NULL);
	xmlRepeater->setAllowResize(Widget::ALLOW_RESIZE_BOTH);

	//create template widget for forum topics' rows
	StackLayout* xmlRowLayout = new StackLayout(0,0,ScreenSize::width(),30,NULL,StackLayout::SL_HORIZONTAL);
	mLayout->add(xmlRepeater);

	Label* forumTitle = createLabel("Topic X");
	forumTitle->setHeight(30);
	forumTitle->setBackgroundColor(GREEN);
	forumTitle->setAllowResize(Widget::ALLOW_RESIZE_X_ONLY);
	forumTitle->setDataXPath("a:Name");
	xmlRowLayout->add(forumTitle);

	Button* showButton = createButton("Show");
	showButton->setAllowResize(Button::ALLOW_RESIZE_Y_ONLY);
	showButton->setWidth(60);
	xmlRowLayout->add(showButton);
	/**/

	xmlRepeater->addItemWidget(xmlRowLayout);

	XmlDocument* xml = XmlToData::toXml(XML);

	xmlRepeater->dataBind(xml->rootNode,"/s:Envelope/s:Body/GetTopicListResponse/GetTopicListResult/a:Topic");

	/* We don't want to add any other new widgets, so just show the soft keys at the bottom */
	addSoftKeys();
}

/* This is the code for the destructor.  This helps us delete widgets and other objects from
 * memory when we've finished. */
HomeScreen::~HomeScreen()
{
	/* Widgets will be destroyed in the BaseScreen destructor */
}

Specifically, the line

xmlRepeater->addItemWidget(xmlRowLayout);

Is required.  What you've got is 

xmlRepeater->add(xmlRowLayout);

Which will add the StackLayout to the repeater, but it won't be the item template.  

There are three types of widget you can add, the header, the item and the footer.  When data is bound, it clones the headers and processes the data first, adding it at the top of the list.  Then it clones the item widget for each item in the data.  Then finally it does the footer in the same way as the header.

Because the template was assigned with ->add() then it will be added to the XMLRepeater's ListBox, but not actually repeated. Is this clear?

XMLReader - I think that this must be a VS issue - I've never seen that error and I've just built this example this morning with no problems (no warnings, no errors).  I'll look into it.

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Good Afternoon,

Thanks for your help Sam, the repeater is working now like a charm. One missing word...
As for the XMLReader, the situation was in Mosync 2.7, and in Mosync IDE.
I have tried it with the Appmancer starter template, and also got the same error.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Ah yeah, I've found it. How did this ever compile. I've never noticed a problem until now. Anyway I can see that there is a problem and I'm on it right now.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Thanks for this - its a good spot.

The problem was with making XmlReader and XmlWriter 'friends' of XmlNode, which was creating a circular dependency.

I've fixed it, and the patched code will go into AppMancer 3.0, which will be released at the same time as MoSync 3.0. I have included the patched source and compiled libraries for MoSync 2.7 below.

This is the test app, using your Xml from the SOAP call.

#include <MAUtil/Moblet.h>
#include <conprint.h>
#include "MAHeaders.h"
#include <AMXml/XmlReader.h>
#include <AMXml/XmlWriter.h>
#include <AMXml/XmlDocument.h>
using namespace AMXml;

#define LOG printf

/**
 * A Moblet is a high-level class that defines the
 * behaviour of a MoSync program.
 */
class MyMoblet : public Moblet
{
public:
	/**
	 * Initialize the application in the constructor.
	 */
	MyMoblet()
	{
		// Test the XML in the file Demo.xml

		// 1. Read the XML into a string.  The utility file XmlToData does this for us, but
		//    we'll do it here again to be clear.
		int len = maGetDataSize(XML);
		char xmlbuffer[len + 1];
		maReadData(XML, xmlbuffer, 0, len);
		xmlbuffer[len] = '\0'; //Null terminator
		LOG("XML Input:");
		LOG("xmlbuffer");

		// 2. Create an XML reader and parse the XML into it.
		XmlReader xr;
		XmlDocument* xml = xr.parseXML(xmlbuffer);

		LOG("Xml Parsed");
		LOG("RootNode '%s'", xml->rootNode->getName().c_str());

		// 3. Create an XML writer, and write the XML out again
		XmlWriter xw;
		String outputxml = xw.toFragment(xml->rootNode);

		LOG("Xml written");
		LOG(outputxml.c_str());

		printf("Press zero or back to exit\n");
	}

	/**
	 * Called when a key is pressed.
	 */
	void keyPressEvent(int keyCode, int nativeCode)
	{
		if (MAK_BACK == keyCode || MAK_0 == keyCode)
		{
			// Call close to exit the application.
			close();
		}

		// Print the key character.
		printf("You typed: %c\n", keyCode);
	}

	/**
	 * Called when a key is released.
	 */
	void keyReleaseEvent(int keyCode, int nativeCode)
	{
	}

	/**
	 * Called when the screen is touched.
	 */
	void pointerPressEvent(MAPoint2d point)
	{
		// Print the x and y coordinate.
		printf("You touched: %i %i\n", point.x, point.y);
	}
};

/**
 * Entry point of the program. The MAMain function
 * needs to be declared as extern "C".
 */
extern "C" int MAMain()
{
	Moblet::run(new MyMoblet());
	return 0;
}

To install the fix, replace the header files in include/AMXml with these versions, and replace AMXml.lib and AMXmlD.lib in lib/pipe with the ones in the zip file.

 

 

AttachmentSize
AMXml.zip 150.92 KB
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hey Teddybee, remember this?

Quote:

Is there an opportunity to bind Vectors of domain classes or SimpleLists into the repeater directly?

Have a look at this thread - :-) http://www.mosync.com/content/ui-data-binding

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Good Morning,
I saw It yesterday, It's unbelievable how fast do you solve that. :) I had similar idea to reach by names to domain data class properties, after it can be use by path.
---
I am thinking about another helpful things:
Is there a serializer/deserializer mechanism in Appmancer? It would be faster easier programming for example the SOAP requests, or simple xml to class(which will be IComparable I guess ). The parameters can be similar to databinder, with an additional optional mapping schema object, that can be handle namespaces(or other possibility, putting directly the schema inside serializable data object).
---
I have also a silly questions, I am very new in Mosync and Appmancer, and lately programming a lot with c#. How can I achieve to fire/route event to appropriate handler in embedded widget, e.g.: a button clicked event in my xmlrepeater example above? Should I use triggers for that?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi,

I'd love to be able to do automatic serialization, deserialization of object like you can in C#. The problem comes back to lack of support for reflection in C++. I could produce an interface to let you build classes which will serialise, but it would add so much work onto what you have to do to build the class that I think it would be easier for you to write a new serialiser for each class. That's what I do anyway.

Buttons in ListBoxes behave in a slightly different way as the ListBox needs to capture the touch event rather than the Button. What would be a more typical scenario is that each entry in a ListBox is selectable. To find out which item has been selected, you need to implement ListBoxListener in a class, normally in a screen. This has a method itemSelected() which is called when the user picks an item from the list box. You can use this to determine which option has been selected and what to do. This code will work for NativeUI listboxes and AMUI listboxes, so you don't need to handle them differently.

This is some code I use for menu screens, which are essentially just a ListBox of options. Have a look at it and see how the item selection works.

AttachmentSize
Menu.zip 2.5 KB
Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Thanks for the help, I try it.
If I will have some free time, I will do a serializable object thing with Appmancer 3(hope I can :) ).

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Hi Sam,
I would like to use your Editbox in dualUI, but there is no parent pointer in the NativeEditBox declaration, but the example contains it. Which one is the working, true? :) ( I saw only a big black hole instead of textbox )

https://appmancer.repositoryhosting.com/trac/appmancer_appmancer30/wiki/AMUI/NativeEditBox

---
Another strange thing, that I find with labels, if i change the label background to black, it will not change (keep it green) but, if I rewrite the word to white, it is working...

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

The example is wrong, I'll fix it.

If you are using DualUI, do not assign parents in widget constructors. It is only there for MAUI compatibility, and it just won't work in NativeUI mode (its all to do with C++ constructor precedence). Its fine in non-native mode, and I might be able to do something in the future, but it means adding extra code to all the widgets (which is fine), but makes it harder for other people to implement new widgets (which is not fine). My advice is to always pass NULL in the parent parameter, and call mParent->add(mChild);

Thanks for spot!

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Btw - did you see the new video - http://www.screencast.com/t/tLfb1z65UjXc

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Its newer than the last one about list binding, the new linq kind sorting and ordering is very cool !
I also have some questions: What do you is this binding can work also in dual way?
Is there possibility to Widgets will get Tag properties? (its very usefull in lots of cases)
Layouts also can have some configurable event broadcasting mechanism, to help embedded layouts events.
Did you know about something, when will be the mosync 3 and appmancer 3 out officially?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hey,

Yes this will bind both NativeUI and non native widgets.

What do you mean by Tag properties?

I think I know what you mean about embedded events. It is possible to get them to report events to a central mechanism, but I'd want to make sure that it was done for the right reasons. Normally, I would create all the layouts in the same screen, so the screen can be the listener if it needs to be. What did you have in mind?

AppMancer 3 will be out when I've tested it with the release version of MoSync 3. I'm currently helping out with some documentation, and Windows Phone 7 support is just being finished off. It is really close now, maybe next week? I need to check DeclarativeUI for AM 3.0, and test ADO objects and their DataBinder.

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

I mean data binding can be used not just for reading data from xml, but if data changes, for example in texbox or slider, the changes can commits also in xml too. (bit it was a silly question, ADO objects will doing this exactly the same in 3)
---
Tag properties can store a string that can be used for anithing to store a litle peace of information in connection with the widget easily (like item Id in button that can be used to make a command parameter after pushing that particular button )
---
Embedded layouts, when I tried my example you helped me, doesnt fire events when I want to push a button in xmlrepeater. xmlrepeater has stacklayout items, and this layout contains a button, currently I use the Listbox selecteditem event in rows, but this is different from do the command only when I pushing the button.
At first sight i thought that IsButton property responsible for forwarding the push event into the inner widgets, but its not. :)
I think, lots of things will be cleaner for me by sample applications...

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

OK, this issue is the ListBox (the XMLRepeater) not the layouts. ListBoxes on non-native UI have to respond to touch events, and disable the IsButton setting. I'll look at testing the selected widget, and if it is IsButton, calling the trigger method.

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Good Afternoon, I ran into interesting thing: Int hat case if somebody(actually me) wants to upload an object to the SOAP service? Parameters working good, if parameters just basic values, but if this is a class, I have to put namespace url-s into the parameter node, also the parameter datamembers into the parameter node, which wasn't worked for me simply put xmlnodes converted by xmlwriter(and by hand copy of xml either). Is there an opportunity to extend soaprequest addparameter with optional namespace attributes to parameters, and/or opportunity to add xmlnode as soaprequest parameter?

Another scenario, where you like to add whole array of classes to parameter.

Here is what my class parametered requests should looks like in WCF:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
	<s:Body>
	    <AddComment xmlns="http://tempuri.org/">
	      <comment xmlns:a="http://schemas.datacontract.org/2004/07/Forum.WcfService.DataContracts"
	                xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
	        <a:Content>ertertert rterterter</a:Content>
	        <a:CreatedAt>0001-01-01T00:00:00</a:CreatedAt>
	        <a:CreatedByName>admin</a:CreatedByName>
	        <a:Id>0</a:Id>
	        <a:Title>rgere rert</a:Title>
	        <a:TopicId>4</a:TopicId>
	      </comment>
	    </AddComment>
	  </s:Body>
</s:Envelope>
		 	
Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

UPDATE:

After a little investigation, these are the results. Using escape characters in simple String addparameter can put class datamembers to request:

//It is working, except putting namespaces
String commentStr = "<param1>rterte<\/param1>"
"<param2>675<\/param2>";
LOG("%s",commentStr.c_str());
soapReq->addParameter("comment", commentStr);

With XmlWriter, it isn't working:

XmlNode* commentXmlNode = comment.serialize();
String commentXmlStr = xmlWriter.toFragment(commentXmlNode);
int len = commentXmlNode->getName().length()+2; //<a:Comment>
String commentStr = commentXmlStr.substr(len,commentXmlStr.length()-(len + len+1));//cuts the root node
delete commentXmlNode;
LOG("%s",commentStr.c_str());
soapReq->addParameter("comment", commentStr);

Logs shows the content, that I would like to put inside is good, but the result that send mosync to the service looks like this:

<?xml version = "1.0" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddComment xmlns="http://tempuri.org/">
      <comment

 

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Are you using AMDownload (or even AMSOAP) for this? Writing is asynchronous. If the String goes out of scope, then the data will be destroyed before the writing has completed. AMDownload is the safe and easy way to send the data.

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Yes, I use AmSoap. Maybe you are right, but in this case how could be good the first code snippet? I give strings to the request object the same way. (and also I used it perfectly to simple parameters too) Also until request haven't sent, the variable stay in the scope.

Anyway, I am overwriting your AMSoap library just now, maybe it will be little simpler and little more flexible.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, I'm making some changes then to AMSOAP for version 3.0.

AMXml doesn't *really* support namespaces, but they don't cause it generate errors or anything. When you set an XmlNode name like "<soap:username>", it will set the name property to 'soap:username', the prefix property to 'soap' and the localname property to 'username'.

XmlWriter only uses the name property when it is writing, which works if this is Xml you've read in from another source, but not so good when you're generating it.

I'm changing it so that if there is a prefix, XmlWriter will write out '<prefix:localname>' and if there isn't one, it will write '<name>'.  I'm also going to add a setPrefix or setNamespace method to XmlNode.  I prefer setPrefix because setNamespace infers things that XmlNode doesn't do.  So when you're serialising your object, you can use the proper name of the property, and supply a prefix for soap.

I've just tested the current XmlWriter with your XML. This is the XML it wrote:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Body>
  <AddComment xmlns="http://tempuri.org/">
    <comment xmlns:a="http://schemas.datacontract.org/2004/07/Forum.WcfService.DataContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <a:Content>ertertert rterterter</a:Content>
      <a:CreatedAt>0001-01-01T00:00:00</a:CreatedAt>
      <a:CreatedByName>admin</a:CreatedByName>
      <a:Id>0</a:Id>
      <a:Title>rgere rert</a:Title>
      <a:TopicId>4</a:TopicId>
    </comment>
  </AddComment>
 </s:Body>
</s:Envelope>

So it really should work right now, if when you are serialising you add 'a:' to the beginning of the properties.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

OK, I've done those changes. You can download new source for AMXml and AMSOAP from the repo at http://appmancer.repositoryhosting.com and build new libraries if you want.

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Good Morning!
That's why I burning the midnight oil? :) I have done it also yesterday, I would like to extend it with a little conventional automatization and to working with Vectors of XmlNodes (domain class serializations), but it is also working fine. (attached below)
Thanks to your attention to the issue. The root cause was the namespaces, I use a monitoring stuff that shows me the xml, and the deserialization failed half a way, becouse it cant find the object's namespace definition in the xml, and also I get http 500 error back from service.
Another thing, if my request wrong, amsoap fire also the request complete function, but if there isn't a 200OK response, the request probably get error back (4xx and 5xx HTTP responses I am sure sign for this) is it a normal behavior?

AttachmentSize
AMSoap.zip 3.45 KB
Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Here is the slightly upgraded version, it is also working fine with array parameters (tested).

AttachmentSize
AMSoap.zip 3.59 KB
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

That's cool. I really like the idea of passing a whole map of parameters in. I can imagine how that could make configuration easy for someone. I need to add the ability to add parameters to soap:header as well as soap:body as well, and then I think that it would be really powerful, but still very simple for simple soap calls.

requestComplete is always called so users know when their request is finished with and they can delete their SoapRequest object.

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Good Afternoon, I had also an issue with appmancer, in adition to not get a simple NativeEditBox worked in mosync and adroid emulator, there is another issue (maybe it is just in my code). I would like to validate a bunch of editboxes before I save/send the data, I wrote a little helper method:

static bool isValid(NativeEditBox* editbox)
	{
		LOG("isValid()");
		if(editbox == NULL)
			LOG("ERROR!!! editbox is NULL");

		bool valid = true;
		Vector<ValidationRule> validators = editbox->getValidators();
		LOG("validators size: %d", validators.size());

		//validation
		Validator* validator = NULL;
		for(Vector<ValidationRule>::iterator itr = validators.begin(); itr!= validators.end(); itr++)
		{
			validator = (*itr).getValidator();
			if( validator != NULL )
			{
				LOG("***");
				valid = validator->validate(editbox, (*itr).getTestValue()) && valid;
			}
		}

		return valid;
	}

But, the

(*itr).getValidator()

always give me a NULL pointer... (I added a validator into the editboxes before )

Is there an easier way to validate these boxes, or opportunity to put that kind of logic into validatable widgets? (like: widget->isValid(), and as I saw maybe ValidationRule also should be contains a function like this: ValidationRule::validate(ValidatableWidget* vwidget)     )

 

 

 

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

PS: Don't you thinking about adding function pointers to handle widget actions, like buttonClick and others?

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

The problem was in my moblet, I used WidgetWarehouse, write everything fine, except calling a function loadWidgets in Load... :S
---
Other thing that would be nice, I am using XmlRepeater with StackLayouts, but I cant get it set the heights to auto(depending on inner widgets) like other widgets, so it is not as flexible as I need. Is there any other Widget that capable for that?

Merdica2
Merdica2's picture
Offline
Mobile Conjurer
Joined: 23 Feb 2012
Posts:

Hello,

I tried the AppMancer and liked it, but I'm not sure if I can build also WP7 apps with NativUI or only iOS and Android apps?

Thanks

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Cool, yeah, it is a collection of libraries built on top of MoSync, so if MoSync supports it, then AppMancer will also work.  I've not added Panorama in yet to the UI library.  If you come across features (particularly NativeUI features) you want, please let me know.  I'm trying to keep it up to date with the MoSync releases.