6

I have prepared some code that builds a collection. I would like to use this collection in LINQPad for various queries. As LINQPad allows WCF OData I thought that MVC4 WebApi would be perfect for this.

Unfortunatelly I wasn't able to make this work even with the template WebApi project. When I try to add service to LINQPad I get "Data at the root level is invalid. Line 1, position 1. I think the problem is that LINQPad doesn't use content negotiation and it is expecting xml but WebApi returns json.

Unfortunatelly Fiddler wasn't able to monitor the requests.

Anyone know how to fix this?

j0k
  • 22,600
  • 28
  • 79
  • 90
bodziec
  • 574
  • 1
  • 6
  • 23

2 Answers2

1

LinqPad does not have the REST drivers by default to query a Web API service. See: http://forum.linqpad.net/discussion/199/linqpad-error-when-access-odata-using-webapi

However, the following blog post by Filip W. speaks to this issue and how you can create a custom ControllerResolver that overrides the default resolver and allows running Web API from LinqPad. Have a look:

Hosting ASP.NET Web API in LinqPad

This post follows the same question: Using WebAPI in LINQPad?

Community
  • 1
  • 1
atconway
  • 20,624
  • 30
  • 159
  • 229
0

why don't you just use the HttpClient class? HttpClient

Helikaon
  • 1,490
  • 13
  • 30
  • Can you give me more details? – bodziec Apr 02 '12 at 08:43
  • take a look at this post [link](http://www.johnnycode.com/blog/2012/02/23/consuming-your-own-asp-net-web-api-rest-service/) specifically at the client implementation. HttpClient is part of the Web API itself and allows you for building simple clients for REST services. Alternatively you could query your Web API Web Service using a normal web browser writing your queries directly in address bar like: http://services.odata.org/OData/OData.svc/Categories(1)/Products/$count – Helikaon Apr 02 '12 at 08:54
  • Thanks, I will take a look at this link. Querying through browser is not what I want. I would like to use LINQ in LINQPad to write queries. – bodziec Apr 02 '12 at 09:13