WCF Data Service gives 404 when making OData requests for derived types

只谈情不闲聊 提交于 2019-12-01 08:42:27

问题


I think I'm missing a trick getting WCF data services/OData/Inheritance working; I've created a couple of simple tables:

create table Super 
(
superID int IDENTITY(1,1) not null PRIMARY KEY, 
supername nvarchar(55),
)


create table sub
(
superID int not null,
extraData nvarchar(100),
FOREIGN KEY (superID) REFERENCES Super(superID)
)


insert Super values('abc')
insert Super values('def')
insert Super values('ghi')
insert Super values('jkl')
insert Super values('mno')


insert sub values(1, 'pqrstu')
insert sub values(3, 'vwxyz')

Pulled them into an edmx, replaced the relationship auto created with an inheritance one, which generates:

namespace WebApplication3
{
#region Contexts

public partial class Entities : ObjectContext
    {        ....    }

#endregion

#region Entities

[EdmEntityTypeAttribute(NamespaceName="Model", Name="sub")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class sub : Super
    {
    #region Factory Method
    ...
    #endregion
    #region Primitive Properties

    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
    [DataMemberAttribute()]
    public global::System.String extraData
    ...

    #endregion

    }


[EdmEntityTypeAttribute(NamespaceName="Model", Name="Super")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
[KnownTypeAttribute(typeof(sub))]
public partial class Super : EntityObject
    {
    #region Factory Method
    ...

    #endregion
    #region Primitive Properties


    [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Int32 superID
    ...


    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
    [DataMemberAttribute()]
    public global::System.String supername
    ...

    #endregion

    }

#endregion

}

set up the service to use V3:

namespace WebApplication3
    {
    public class WcfDs : DataService<Entities>
        {
        public static void InitializeService(DataServiceConfiguration config)
            {
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
            }
        }
    }

Querying the Supers works fine :

http://localhost:8384/WcfDs.svc/Supers

I've tried a host of URLs in a vain attempt to get the derived types:

http://localhost:8384/WcfDs.svc/Supers/Model.sub/
http://localhost:8384/WcfDs.svc/Supers(1)/Model.sub/
http://localhost:8384/WcfDs.svc/Supers/WebApplication3.sub/
http://localhost:8384/WcfDs.svc/Supers(1)/WebApplication3.sub/
....

but I always get a 404 Resource not found response. What am I missing?


回答1:


And the trick is:

Switch from using the Visual Studio Development server to use the Local IIS in the project properties.

At least, this worked in my VS 2010 environment.



来源:https://stackoverflow.com/questions/16790088/wcf-data-service-gives-404-when-making-odata-requests-for-derived-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!