task-parallel-library - .Net 4.5 Svcutil 生成两个同名操作(Method 和 MethodAsync)

标签 task-parallel-library visual-studio-2012 svcutil.exe .net-4.5 async-await

我正在使用 svcutil a la 使用预定义的 wsdl:

svcutil some_service.wsdl

生成的方法之一具有以下签名:

[System.ServiceModel.OperationContractAttribute(Action="http://ws.example.org/SubmitData", ReplyAction="*")]
SubmitDataResponse SubmitData( SubmitDataRequest request )

虽然来自 VS2010/.net35 的 scvutil 仅生成上述内容,并且 VS 启动服务没有问题,
作为 VS2012/.net45 一部分的 svcutil 程序也会生成一个带有签名的方法

[System.ServiceModel.OperationContractAttribute(Action="http://ws.example.org/SubmitData", ReplyAction="*")]
Task<SubmitDataResponse> SubmitDataAsync( SubmitDataRequest request );

这会导致运行时异常:

System.InvalidOperationException: Cannot have two operations in the same contract with the same name, methods SubmitDataAsync and SubmitData in type MyType violate this rule. You can change the name of one of the operations by changing the method name or by using the Name property of OperationContractAttribute.



我可以通过删除 Async 附加方法或简单地使用 VS2010 中的 svcutil 来解决此问题。但我想知道为什么 svcutil 会生成一个导致运行时异常的接口(interface)(这是一个错误吗?),以及我是否应该做一些额外的事情来使它工作。

最佳答案

默认行为似乎已更改。如果您提供/syncOnly 参数,它会为我保留旧行为。

 /syncOnly                          - Generate only synchronous method
                                  signature. Default: generate synchronous
                                  and task-based asynchronous method
                                  signatures.

关于task-parallel-library - .Net 4.5 Svcutil 生成两个同名操作(Method 和 MethodAsync),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11546431/

相关文章:

由于 WSDL 中存在多个同名类型,WCF 生成的代理抛出 InvalidOperationException

.net - 使用 .NET 4.0 中的任务并行库等待所有任务完成

c# - 为什么异步 Parallel.ForEach 中的异常会使应用程序崩溃?

asp.net-4.0 - Parallel.Foreach 维护集合顺序?

c++ - MSVC 编译器更新

c# - WCF 服务引用命名空间与原始命名空间不同

c# - 并行运行两个异步任务并在 .NET 4.5 中收集结果

visual-studio-2012 - 更改组件文件夹的位置

JavaScript - 在循环中创建div数量