Dynamically create json using WCF service to feed MTDialog application - wcf

I wish to create a MonoTouch MTDialog-based app that upon launching adds a single element to the MonoTouch Dialog and then render the screen. This single element will be a JsonElement similar to this -
var je = new JsonElement ("Dynamic Data", "http://tirania.org/tmp/demo.json");
as shown in the sample application. However, instead of referencing a pre-built json file on a server, I wish to have the url point at a WCF OData service which will dynamically build the json data.
I am not sure what is the easiest way to do this. I am a bit lost after reading over the documentation. Is there some library I can include in my server-side C# app which I can then use to build out the elements and return as a json string of information?
I already have a WCF application up and running and just need to add an entry point which will call the method to create some simple json data for MonoTouch dialog to consume.
Any examples or suggestions are greatly appreciated as I am trying to get a simple solution completed by this weekend.

You're looking for a C# JSON library? How about JSON.NET http://james.newtonking.com/pages/json-net.aspx
You might also look at ServiceStack.NET -- they have a MonoTouch client.

Related

How to render Web Api to a view?

I wrote some code in webapi ValueConroller. When I try to execute it I'm getting JSON data which is by default saving to text file (IE 8.0), XML output when tried with Mozilla Firefox .
I am not sure how to display my List<country> which will be having list of countries and i am writing this method in value controller like
public IEnumarable<countrylist> getcounrty()
{
obj.method1().tolist(); // method1 will return list<country> where country is a class in my BLL
}
I want the method output to be bonded with Dropdownlist . Becoz there is no VIEW is webapi I am confused how to do it
Any ideas are appreciated.
EDIT : konckout.js is a alternative ? my colleagues ad-viced me so any best alternative mates
Web API and MVC have different purposes.
The purpose of ASP.NET Web API is to build HTTP-based web services (also sometimes called REST services). Out of the box, it only supports
JSON
XML
although you can implement other formatters yourself, if you need to exchange data in another format. In theory, you could write a custom formatter to produce HTML, but there's no reason to do that.
If you need to produce HTML, then use ASP.NET MVC.

Use WCF DataService in application

I have an MVC 3 application and create my own WCF data service. I imported in application as service references and service.edmx was automatically created. But when I try to open it, I only see a generic page:
The entity data model designer is unable to display in the file you requested.
I push right click on the page and try “Add Code Generation Item...”, it gives me an error:
Command 'Project.AddNewItem' is not available.
Can I generate .tt files in some other way?
I found the anser: Is not posible.
And if someone whant to use WCF DataSource, an inportant thing: You can't use a lot of reserved word in linq : like JOIN, GROUP, etc...

Consuming a WCF Rest Service with WP7

I have a WCF Restful Service that returns JSON objects that my iPhone and Android apps consume nicely. This is my first attempt at building something like this and I left WP7 till last as my background lies with C# and VS2010. But it seems it’s not going to be a simple as I had guessed.
So I guess I have three questions:
1, Can I consume JSON objects in WP7? If so does anyone know of a tutorial?
2, if not, can I use the existing service and build some new contracts for consumption in WP7? Or,
3, do I need to build a whole new service?
Option one is most desirable but either way, I need to develop for all three operating systems so does anyone know the best type of model to bring this all together???
Cheers,
Mike.
Yes, but not with the channel factory / proxy programming model which you may be used to with WCF. REST services are usually consumed by using some simpler classes such as WebClient. You can use the JSON libraries (DataContractJsonSerializer is in the WP7 profile) then to deserialize the data you receive. Even the untyped JSON (the System.Json classes from the System.Json.dll on Silverlight), while not officially in the profile, they kind of work on WP7 as well (I've seen a few people simply referencing the SL library on a WP7 project).
If you want proxy support, you can add a new endpoint to the service using BasicHttpBinding, which is supported in WP7; if you don't need it, see 1).
No. See 1) and 2).
Try this to deserialize a JSON object:
public static T Deserialize<T>(string strData) where T : class
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
byte[] byteArray = Encoding.UTF8.GetBytes(strData);
MemoryStream memoryStream = new MemoryStream(byteArray);
T tRet = serializer.ReadObject(memoryStream) as T;
memoryStream.Dispose();
return tRet;
}
I find a totally wcf-based approach more interesting.
This is a good post that addresses this issue
http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx

How to setup JsonWritter for ext.net store

I cannot find the solution for configuring ext.net restful store. Reading and deleting records works good, but I need also update and create functionality. For this I need to send data to WCF (restful) service in Json or XML format. In classic ExtJS I would create a store with JsonWritter, but how to do that in ext.net ? Store doesn't have public property Writter (or similar), so I cannot use ... markup. I also didn't find a way how to set writter later (on the place like Ext.onReady...).
Of course, I can gather all data and call WCF service directly (ajax) and then just refresh the store.
But that is not that nice like it would be when store handles all CRUD operation by itself.
Thanks for any help
Please investigate the following sample
http://examples.ext.net/#/GridPanel/Restful/Overview/

Can I create a WCF workflow using the standard Workflow activity templates?

Is it possible to create a WCF workflow using the standard (Activity template) Workflow activity templates? And, if so, where can I find some samples that DO NOT use the standard WCF service template (WCF Workflow Service template)?
Explanation: I'm trying to discover, load and run workflows at runtime, including workflows with WCF activities. Standard workflows get compiled into types (which makes them easy to discover), however the "WCF Workflow Service" template is an xamlx file, which is added as content and loaded as a manifest stream at runtime. This makes discovery at runtime difficult.
I don't think it is a requirement to use this template to create a service, as the WorkflowServiceHost can take an Activity in its constructor.
I'm trying to keep the task of developing a new WCF service to be discovered, loaded and "executed" (i.e., loaded and listening) at runtime as streamlined as possible.
I have been trying to figure out the same since yesterday and now I stumbled upon a workaround. There is no template for simple workflow (xaml) in VS 2010 when adding new item. If you create a WCF WF Application, you get xamlx. I created a Workflow Console application instead, that gave me a xaml file which I copied to my working project. Once this was done, hosting was simple using WorkflowServiceHost.
string uri = "http://localhost:8008/MyService";
WorkflowServiceHost wsh = new WorkflowServiceHost(new Workflow1(), new Uri(uri));
ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
metadataBehavior.HttpGetEnabled = true;
wsh.Description.Behaviors.Add(metadataBehavior);
wsh.AddServiceEndpoint("IService", new BasicHttpBinding(), uri);
wsh.Open();
Yes it is.
This blog post describes how to use an SVC extension instead of a XAMLX and uses a compiles workflow to do so. The comments add some details how to get rid of the SVC file as well. You need to use the WorkflowServiceHostFactory as the Factory to wire things up. You can also do something similar when self hosting.
Actually I just figured out that "Activity" template in add new item is xaml so no need to create that "Workflow console application" to get a xaml file.