Sample or example POSTing and GETing POCOs to WebAPI?
-
Saturday, March 10, 2012 3:44 PM
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
All Replies
-
Monday, March 12, 2012 1:01 AM
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://leeontech.wordpress.com/
- Proposed As Answer by Matt SmallMicrosoft Employee, Moderator Tuesday, March 13, 2012 1:28 PM
- Unproposed As Answer by Terrence_ Tuesday, March 13, 2012 2:10 PM
-
Tuesday, March 13, 2012 2:15 PMwhile 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 3:25 PMModerator
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)
- Proposed As Answer by Jeff SandersMicrosoft Employee, Moderator Tuesday, March 13, 2012 3:25 PM
- Unproposed As Answer by Terrence_ Tuesday, March 13, 2012 3:33 PM
- Proposed As Answer by Jeff SandersMicrosoft Employee, Moderator Wednesday, March 14, 2012 3:13 PM
-
Tuesday, March 13, 2012 3:33 PMJefff, 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
-
Wednesday, March 14, 2012 3:13 PMModerator
No, I no of no sample, but CRUD is simply adding the Create, Read, Update and Delete methods to your webservice.Jeff Sanders (MSFT)
- Proposed As Answer by Jeff SandersMicrosoft Employee, Moderator Wednesday, March 14, 2012 3:13 PM
-
Wednesday, March 14, 2012 4:20 PM
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 5:12 PMModerator
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:
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 6:26 PM
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:30 PMModerator
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)
- Proposed As Answer by Jeff SandersMicrosoft Employee, Moderator Wednesday, March 14, 2012 6:30 PM
-
Wednesday, March 14, 2012 6:32 PM
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:33 PMModerator
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:35 PMI 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:39 PMModerator
I will see if I can track down some additional info for you on this.
-Jeff
Jeff Sanders (MSFT)
-
Wednesday, March 14, 2012 7:31 PM
>>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:48 PMModerator
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:53 PM
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
-
Thursday, March 15, 2012 2:47 AMJeff, 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 12:14 PMModerator
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)
-
Monday, March 26, 2012 8:56 AM
-
Monday, March 26, 2012 3:28 PMThank you Baba, I will check that post out.
Thanks, Terrence
-
Wednesday, April 04, 2012 2:55 AMBaba, 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:56 AM
and what the H E double LL is baba and the pigman / spam ?
Thanks, Terrence
-
Wednesday, April 04, 2012 9:01 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 :-)
-
Wednesday, April 04, 2012 2:35 PM
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


