【问题标题】:WCFDataService Returning BooleanWCFDataService 返回布尔值
【发布时间】:2012-05-17 16:44:49
【问题描述】:

我正在尝试使用 WCFDataServices 执行任务。

我有一个 Service 操作 Like

[WebInvoke(Method="POST")]

公共 bool Add(string x1, string x2, string x3)

{

// 向数据库添加一条新记录。如果添加成功,则返回 true 或 false

}

在我的 MVC 客户端应用程序中。在存储库中,我有添加喜欢的功能

public bool Add(string y1, string y2, string y3)

{

// 在这里我要执行 URI 并捕获返回的值。并将其传递给我的控制器以在视图中显示一些操作。

}

我的服务没有任何问题。它按预期返回布尔值。

我不知道如何在我的存储库方法中捕获返回的布尔值。

// OperationResponse x = dsContext.Execute(requestUri, Microsoft.Data.OData.HttpMethod.Post);

我试图做类似上述的事情。但没有奏效。

感谢您的宝贵时间

【问题讨论】:

    标签: wcf-data-services odata


    【解决方案1】:

    我假设您在客户端上使用 WCF Data Services 5.0(因为您使用的是带有方法的 Execute)。请升级到 RTM 位 (http://blogs.msdn.com/b/astoriateam/archive/2012/04/09/wcf-data-services-5-0-rtm-release.aspx),它们也可用在 NuGet 上(搜索 Microsoft.Data.Services.Client)。之后这段代码应该可以正常工作:

    public bool Add(string x1, string x2, string x3)
    {
         return this.ctx.Execute<bool>(
             new Uri("Add", UriKind.Relative),
             "POST",
             /*singleResult*/ true,
             new UriOperationParameter("x1", x1),
             new UriOperationParameter("x2", x2),
             new UriOperationParameter("x3", x3))
             .Single();
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-18
      • 2011-12-14
      • 2020-07-29
      • 2014-12-13
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 2012-05-10
      • 2018-08-22
      相关资源
      最近更新 更多