Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing WebAPI in LINQPad?
    primarykey
    data
    text
    <p>When I tried to use the Selfhosted WebAPI in LINQPad, I just kept getting the same error that a controller for the class didn't exist. </p> <p>Do I have to create separate assemblies for the WebAPI (Controllers/Classes) and then reference them in my query?</p> <p>Here's the code I'm using</p> <pre><code>#region namespaces using AttributeRouting; using AttributeRouting.Web.Http; using AttributeRouting.Web.Http.SelfHost; using System.Web.Http.SelfHost; using System.Web.Http.Routing; using System.Web.Http; #endregion public void Main() { var config = new HttpSelfHostConfiguration("http://192.168.0.196:8181/"); config.Routes.MapHttpAttributeRoutes(cfg =&gt; { cfg.AddRoutesFromAssembly(Assembly.GetExecutingAssembly()); }); config.Routes.Cast&lt;HttpRoute&gt;().Dump(); AllObjects.Add(new UserQuery.PlayerObject { Type = 1, BaseAddress = "Hej" }); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; using(HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Server open, press enter to quit"); Console.ReadLine(); server.CloseAsync(); } } public static List&lt;PlayerObject&gt; AllObjects = new List&lt;PlayerObject&gt;(); public class PlayerObject { public uint Type { get; set; } public string BaseAddress { get; set; } } [RoutePrefix("players")] public class PlayerObjectController : System.Web.Http.ApiController { [GET("allPlayers")] public IEnumerable&lt;PlayerObject&gt; GetAllPlayerObjects() { var players = (from p in AllObjects where p.Type == 1 select p); return players.ToList(); } } </code></pre> <p>This code works fine when in a separate Console Project in VS2012.</p> <p>I started using AttributeRouting via NuGET when I didn't get the "normal" WebAPI-routing to work.</p> <p>The error I got in the browser was: <code>No HTTP resource was found that matches the request URI 'http://192.168.0.196:8181/players/allPlayers'.</code></p> <p>Additional error: <code>No type was found that matches the controller named 'PlayerObject'</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload