locked
Sample or example POSTing and GETing POCOs to WebAPI?

    Question

  • Now that the Consumer Preview has been out for 10 days, is there an example or a sample showing the following:

    POSTing and GETing a POCO from a Metro Xaml/C# to a WebAPI webservice.?

    There are many examples that demonstrate how to get a simple string to a from a webservice, but those examples to don't show the serialization and deser. of a poco object.

    I am particularly interested in out of the box solutions rather than using lots of 3rd party libraries.


    Thanks, Terrence

    Saturday, March 10, 2012 3:44 PM

Answers

All replies

  • I was able to write a console application that uses ASP.NET Web API to host an HTTP service and then use that from metro app.

    http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api

    http://blogs.msdn.com/b/henrikn/archive/2012/02/20/asp-net-web-api-and-httpclient-available-on-nuget.aspx


    http://leeontech.wordpress.com/

    Monday, March 12, 2012 1:01 AM
  • while the links you provided point to how to self host a webapi and how to get webapi bits, they do not give a demonstration of how to do CRUD against the api.  Building the api is easy.  The client side examples in metro is what we have a lack of.

    Thanks, Terrence

    Tuesday, March 13, 2012 2:15 PM
  • This shows the WCF implemented functionality.  You will need to use one of those serializers (also a stick at the top of the forum):

    http://blogs.msdn.com/b/piyushjo/archive/2011/10/19/wcf-for-metro-apps-supported-functionality.aspx

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, March 13, 2012 3:25 PM
    Moderator
  • Jefff, do you know where the sample app or example code is for a Consumer Preview Metro Xamp app is doing CRUD against a webservice?  That link just shows the what is supported.  I know it is supported, I just want to look at some code.

    Thanks, Terrence

    Tuesday, March 13, 2012 3:33 PM
  • No, I no of no sample, but CRUD is simply adding the Create, Read, Update and Delete methods to your webservice.

    Jeff Sanders (MSFT)

    Wednesday, March 14, 2012 3:13 PM
    Moderator
  • Jefff, I am not asking about how to write the webapi, that is the easy part.  This forum post is about Posting and Geting data from a webapi...ie the client end of the deal.  That is not a trivial matter, and it is odd that there are no examples using the HttpClient provided in the consumer preview.

    I must not be describing my problem clear enough.


    Thanks, Terrence

    Wednesday, March 14, 2012 4:20 PM
  • Hi Terrence,

    Using HttpClient would be difficult but not impossible.  Request after all are simply HTTP requests so you could inspect and craft the requests manually.  Most everyone developing Metro style apps today has found the Service Reference path to be the best way.  You do this very similar to how you would have done this in the past.

    At the top of this forum is a sticky post that has some more information:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/c45a1ae5-05f3-42dc-8bc8-3b62d8ee5f7b

    Also check out this blog for many samples:

    http://blogs.msdn.com/b/piyushjo/

    Is that sufficient?

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by Terrence_ Wednesday, March 14, 2012 6:32 PM
    Wednesday, March 14, 2012 5:12 PM
    Moderator
  • Stop the presses!  I was under the impression that adding Service Reference did not work.  Of couse I was trying to hit a WCF Data Service and that client is not avaiable to the metro client.

    So are you saying that I can Add service reference and point it to my mvc webapi service and it will build a client proxy for me?  I am at work and my metro slate is at home so I can't check that out now.  If that is the case, I am in business.

    Plesae confirm.


    Thanks, Terrence

    Wednesday, March 14, 2012 6:26 PM
  • Oh my Terrence!  No wonder you were confused... Yes: http://blogs.msdn.com/b/piyushjo/archive/2011/09/22/wcf-in-win8-metro-styled-apps-absolutely-supported.aspx

    There were problems with a couple of scenarios that were cleaned up in the Consumer Preview so code away!  If you run into some problems, please post back.  Also review the posts in Piyush's blog posts.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, March 14, 2012 6:30 PM
    Moderator
  • Thanks Jeff.  Could you confirm or deny that the client for WCF DS works or does not work in consumer preview?

    Thanks for you help.


    Thanks, Terrence

    Wednesday, March 14, 2012 6:32 PM
  • I cannot, I did not think that under the covers there was any difference... Is there?

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, March 14, 2012 6:33 PM
    Moderator
  • I think there is, my conversations with Pablo lead me to believe it does not work at this time.

    Thanks, Terrence

    Wednesday, March 14, 2012 6:35 PM
  • I will see if I can track down some additional info for you on this.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, March 14, 2012 6:39 PM
    Moderator
  • >>I will see if I can track down some additional info for you on this.

    That would be Great.


    Thanks, Terrence

    Wednesday, March 14, 2012 7:31 PM
  • Check this out from Henrik, I think it will fit the bill.  I had not thought about JSON.

    http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee

    http://blogs.msdn.com/b/henrikn/archive/2012/02/16/httpclient-is-here.aspx

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, March 14, 2012 7:48 PM
    Moderator
  • Thanks Jeff, I have read all of Henrik's blog posts.  Most just end up posting or getting a single string.

    I have some code working on getting and posting a poco, but I would just like to see how the smart people are doing it.

    I am going to check out adding the service reference to check what type of proxy it builds for me.  If you hear anything about WCF DS "Add Serv. Ref" please let me know.


    Thanks, Terrence

    Wednesday, March 14, 2012 7:53 PM
  • Jeff, add service reference aiming at a webapi service does not work.  Have you actually tried this?  If so please explain how you got it configured.

    Thanks, Terrence

    Thursday, March 15, 2012 2:47 AM
  • Hi Terrence,

    I am not sure we are talking about the same thing.  Creating a WebService in WCF and then pointing to it with the wizard does definately work.  Is that what you are doing?  Also, you should be able to use OData today to connect if you wish and that should allow you to do what you want.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 15, 2012 12:14 PM
    Moderator
  • Thank you Baba, I will check that post out.

    Thanks, Terrence

    Monday, March 26, 2012 3:28 PM
  • Baba, your blog post was great.  I wonder if you could update it and tell us how you are dealing with DateTime values?

    Thanks, Terrence

    Wednesday, April 04, 2012 2:55 AM
  • and what the H E double LL is baba and the pigman / spam ?


    Thanks, Terrence

    Wednesday, April 04, 2012 2:56 AM
  • Hi Terrence,

    I 'borrowed' the name from an entry in a BBQ competition (not really something we have in the UK and I just thought it was funny). The 'spam' thing is just something I remember eating as a kid but have not really come iinto contact with since :-)


    http://babaandthepigman.spaces.live.com/blog/

    Wednesday, April 04, 2012 9:01 AM
  • Thanks for solving the mystery behind babaandthepigman.

    I shouldn't have posted two posts at the same time.  Maybe you missed my prior post that said this:

    >>Baba, your blog post was great.  I wonder if you could update it and tell us how you are dealing with DateTime values?


    Thanks, Terrence

    Wednesday, April 04, 2012 2:35 PM