Reputation:
This is the only code I have in an otherwise blank web application (.Net 4):
public class Spork
{
public string Name { get; set; }
public DateTime BirthDate { get; set; }
}
public class WcfDataService1 : DataService<Spork>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetEntitySetPageSize("*", 26);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
[WebGet]
public IQueryable<Spork> Get()
{
List<Spork> retval = new List<Spork>();
retval.Add(new Spork() { BirthDate = DateTime.Now, Name = "jason" });
return retval.AsQueryable<Spork>();
}
}
If I go to http://localhost:1285/WcfDataService1.svc/
, I get this response:
<service xml:base="http://localhost:1285/WcfDataService1.svc/">
<workspace>
<atom:title>Default</atom:title>
</workspace>
</service>
So far so good, I guess. Now, I want to get my spork by going to http://localhost:1285/WcfDataService1.svc/Get
. But I get a "Resource not found for the segment 'Get'." error. What am I misunderstanding?
Upvotes: 4
Views: 1354
Reputation: 33149
You're using DataService but Spork is not a data source (Context), it is an entity class.
Try defining your Spork in a data context, for instance using an Entity Framework model or a Linq To Sql model.
Upvotes: 2
Reputation: 1470
It appears you are trying to use REST with WCF. It is possible to do so (see: http://msdn.microsoft.com/en-us/magazine/dd315413.aspx) but by default, WCF is SOAP based. If you want to use URL + verb, you will have to set it up in your web.config.
Good luck!
Upvotes: 0