无需使用实体框架的无类型自定义数据服务提供程序实体的服务操作

时间:2014-02-14 10:46:36

标签: jquery asp.net odata wcf-data-services service-operations

我正在使用C#使用OData生成无类型自定义数据服务提供程序
实现了所有必需的提供者和接口 仅在元数据创建期间动态指定所有实体 不能使用EDMX或反射提供者 提供了所有访问权限。

1)CustomMetaDataProvider

public bool TryResolveResourceType(string name, out ResourceType resourceType)  
{  
    return this.resourceTypes.TryGetValue(name, out resourceType);  
}
public bool TryResolveServiceOperation(string name, out ServiceOperation serviceOperation)  
{
    if (serviceOperations.TryGetValue(name, out serviceOperation))
    {
        serviceOperation.SetReadOnly();
        return true;
    }
    else
    {
        serviceOperation = null;
        return false;
    }            
}

2)CustomDataQueryProvider

public object InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters)
{
//Invoke the method present in ServiceOperation
}

当我提供以下网址时     http:// localhost / SampleService.svc / TestEntity(1)/ Id>
我可以获取id值。

当我使用网址打电话给服务时   http:// localhost / SampleService.svc / TestServiceOperation
我可以调用服务操作。

但是当我尝试调用Serv.Op时。指定实体后,我得到错误
  http:// localhost / SampleService.svc / TestEntity / TestServiceOperation

当我使用这个url时,它找到相应的TestEntityResourceSet,
然后去查找name = TestServiceOperation的resourcetype 但是没有TestServiceOperation的资源类型。 需要在TryResolveServiceOperation中使用相应的SO名称进行搜索。

在网上搜索的所有示例都像调用Ser.Op.仅限.svc / SO类型。
 我需要为每个实体单独调用服务操作。喜欢

http:// localhostTest.svc / Entity1 / SerOp1 http:// localhostTest.svc / Entity2 / SerOp2

如何做到这一点的任何好例子?感谢。

1 个答案:

答案 0 :(得分:0)

好像你正在寻找绑定在EntityType上的动作。见 10.4.1。 OData V3.0 Procotol中的操作了解详情。

相关问题