【问题标题】:svcutil ignores out paramter of async WCF callsvcutil 忽略异步 WCF 调用的参数
【发布时间】:2011-11-27 07:08:32
【问题描述】:

我有一个服务WCF接口:

[ServiceContract(Namespace = "net.pipe://QFX_DLL/TradingService")]
public interface IGenericTradingInterface  {

    [OperationContract]
    void GetServerInformation(out ServerAttributes attributes);
}

此主机已启动并正常运行。我使用 svcutil 创建客户端代理对象如下:

svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config net.pipe://localhost/QFX_DLL/mex /async /tcv:Version35

为异步调用生成的代理如下所示:

public void GetServerInformationAsync()
{
    this.GetServerInformationAsync(null);
}

如您所见,out 参数属性完全丢失了!非异步方法看起来不错。 有了这个 GetServerInformationAsync 声明,我无法取回结果。 这是怎么回事?

【问题讨论】:

    标签: c# wcf asynchronous svcutil.exe out


    【解决方案1】:

    out 参数(和任何结果)将在 EventArgs 类中,该类将传递给 GetServerInformation 完成时触发的事件(可能是 GetServerInformationCompleted)。属性名称可以是 Result(这很可能是只返回 1 个值的操作)或参数名称(属性)。

    【讨论】:

    • 是的,我也想过,但是当我想从这样的结果中读取时: Console.WriteLine("ServerInfo Time: {0}", e.Result.CurrentTime.ToString() );然后我得到一个异常:System.Reflection.TargetInvocationException,所以我认为这是由于缺少参数。
    • 解决方案是,不能对传递给 WCF 方法的 struct 字段进行 get 和 set。再次感谢:-)
    • 检查TargetInvocationExceptionInnerException 属性,它应该为您提供有关该问题的更多信息。而且您当然可以在 WCF 方法上传递的类型上使用 getter/setter,您还有其他问题吗?
    猜你喜欢
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 2012-10-03
    • 1970-01-01
    • 2018-09-07
    • 2022-11-11
    相关资源
    最近更新 更多