Fixed ServiceStack vs ASP.Net Web API #dev #it #asnwer
Fixed ServiceStack vs ASP.Net Web API #dev #it #asnwer
ServiceStack vs ASP.Net Web API
I want to write a new REST style API and have looked at ServiceStack and quite like it. However, I have seen that Microsoft has released the ASP.Net Web API project as part of the new MVC 4 beta. Has anyone looked at the new Web API project? Can you give any pros/cons of each system?
I want to write a new REST style API and have looked at ServiceStack and quite like it. However, I have seen that Microsoft has released the ASP.Net Web API project as part of the new MVC 4 beta. Has anyone looked at the new Web API project? Can you give any pros/cons of each system?
Upgrading Mono on Ubuntu to Work Around Assembly Version Conflict
I ran into a build error on Ubuntu after I added ServiceStack.Logging, though it was building fine in Xamarin Studio. I am using xbuild and I believe the problem was due to conflicting indirect assembly references. (Full error after the break.) I tried a BindingRedirect, but no joy.
I was able to reproduce the symptoms in Xamarin Studio by changing the Mono version to 2.x. So, I concluded I could work around the issue by upgrading Mono on Ubuntu to 3.x. However, the latest Mono package is still working its way through quality control and is not widely available. To get the experimental version here's what you can do:
sudo echo "deb http://debian.meebey.net/experimental/mono /" | sudo tee -a /etc/apt/sources.list sudo apt-get update sudo apt-get install mono-complete ... mono -V
Should yield:
Mono JIT compiler version 3.0.6 (Debian 3.0.6+dfsg-1~exp1~pre1) ...
Symptoms
$ xbuild foo.sln
Yielded many warnings like:
/usr/lib/mono/4.0/Microsoft.Common.targets: warning : Found a conflict between : 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' reference. /usr/lib/mono/4.0/Microsoft.Common.targets: warning : Found a conflict between : 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' reference. /usr/lib/mono/4.0/Microsoft.Common.targets: warning : Found a conflict between : 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' reference. /usr/lib/mono/4.0/Microsoft.Common.targets: warning : Found a conflict between : 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' reference.
This one in particular caught my attention because we are using ServiceStack 3.9.71, but the Logging assemblies reference ServiceStack.Interfaces 3.9.59 and the actual embedded assembly version is 1.0.0.0.
/usr/lib/mono/4.0/Microsoft.Common.targets: warning : Found a conflict between : 'ServiceStack.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Interfaces, Version=3.9.59.0, Culture=neutral, PublicKeyToken=null'. Using 'ServiceStack.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' reference.
Ending with this error:
/usr/lib/mono/4.0/Microsoft.CSharp.targets (CoreCompile target) -> Program.cs(5,28): error CS0234: The type or namespace name `Log4Net' does not exist in the namespace `ServiceStack.Logging'. Are you missing an assembly reference?
Object Serialization as Step Towards Normalization
ServiceStack.OrmLite refers to this as a "text blob" and it is by default how it handles complex data inside a table POCO. So, this is a trivial way to proceed with new data.
For example, we may have a database of food products and now we will be ingesting "Nutrition Facts" per item. Inserting a record as follows:
db.Insert( new FoodItem { Name = "Oatmeal", NutritionFacts = new NutritionFacts { ServingSize = 1, ServingSizeUnits = "cup", Calories = 158, TotalFat = 3.2m } });
Would yield a record with NutritionFacts serialized as compact JSON.
If, in the future, we need to query data we can use a database migration to transform it to a more normalized format. In some cases the POCO may not change much. We can take advantage of ServiceStack.OrmLite's [References] and [ForeignKey] relational attributes to read entities from the more normalized database.
ServiceStack - Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
This looks useful and more mature than ASP.Net Web API 2.However, it couples to the model rather than the controller. I wonder what implications this would have now that Web API 2 has optional routing at the action level?