In this tutorial I will show how easy it is to create Web Services with Service Stack and call them from a MonoTouch application.
You can download the full source code for this tutorial at:
http://servicestack.googlecode.com/files/RemoteInfo.zip.
Alternatively, you can browse all the source code online at:
http://code.google.com/p/servicestack/source/browse/#svn/trunk/MonoTouch.Examples/RemoteInfo
For simplicity we'll start with an existing Mono Develop solution which has already been configured
to host Web Services using Service Stack.
RemoteInfo is an example project that exposes information about a servers'
file / directory structure via XML and JSON Web Services:
The configuration of a ServiceStack Web Service Host is held in the AppHost.cs class.
The contents of RemoteInfo's AppHost.cs is included below.
Configuring ServiceStack as seen in this example is pretty easy, generally the only things you need to do is:
The only thing left to do is to get your configuration to run on start-up which can be done in a Web Application done by adding
protected void Application_Start(object sender, EventArgs e)
{
var appHost = new AppHost();
appHost.Init();
}
to your Global.asax.cs.
If everything is configured properly you should be able to go to the base of your Web Application directory (RemoteInfo.Host.Web) in Terminal and run xsp from the Command Line:
If all went well and you didn't get any errors going to http://localhost:8080 should give you a splash page for your Web Services:
This splash page contains a list of all Web Services available from this Web Application. On the right side of each 'Operation' is the list of different end points that your web service is available from. Other info available includes links to example code on different ways you can call ServiceStack Web Services. As well as the XSD's and WSDL for your web services - useful if you use other tooling to examine and call your Web Services.
Clicking on the XML link for a particular Operation shows a complete example (including HTTP traffic) on how to call the selected web service as well as the response to expect. I find this useful for times when I want to check the output of a Web Service without having to load Mono Develop or VS.NET to find out.