【问题标题】:Async CTP call a wcf ria service method that returns a string value异步 CTP 调用返回字符串值的 wcf ria 服务方法
【发布时间】:2011-09-29 02:03:22
【问题描述】:

我正在尝试在我的 silverlight wcf ria 服务项目中实现以下内容。

http://blogs.msdn.com/b/kylemc/archive/2010/11/02/using-the-visual-studio-async-ctp-with-ria-services.aspx

它适用于实体。但是我正在尝试编写一个返回字符串并引发错误的自定义方法。

自定义方法

    public string GetHello(string str)
    {
        return ("Hello " + str);
    }

从客户端调用

String str;

str = await context.LoadAsync(context.GetHello("Sam")).ToString();

错误:

'await' 运算符要求其操作数 'System.ServiceModel.DomainServices.Client.InvokeOperation' 有一个合适的公共 GetAwaiter 方法

【问题讨论】:

  • 请仔细检查您的示例代码。您确定此客户端代码会导致该错误吗?

标签: silverlight wcf service ria async-ctp


【解决方案1】:

您需要调用AsTaskInvokeOperation 转换为Task

【讨论】:

  • 我试过了,现在我无法将类型 'System.ServiceModel.DomainServices.Client.InvokeOperation' 隐式转换为 'string' hstring = await this.parentWindow.ctx.HashString("asdasd ").AsTask();如果我异步调用它(使用委托),这个方法可以正常工作。但是我使用异步 CTP 和 Kyle 的代码来同步调用该方法。
  • 在您await 之后,请阅读InvokeOperation<string>.Value 成员。例如,(await this.parentWindow.ctx.HashString("asdasd").AsTask()).Value
  • 我找不到 AskTask()。它是在哪里定义的?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-04
相关资源
最近更新 更多