本文介绍了.Net 4.5 Svcutil 生成两个同名操作(Method 和 MethodAsync)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am consuming a predefined wsdl with svcutil a la:

svcutil some_service.wsdl

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

one of the methods generated has the following signature:

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

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

While scvutil from VS2010/.net35 generates only the above and VS has no problem lanuching the service,the svcutil program that is part of VS2012/.net45 also generates a method with the signature

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

这会导致运行时异常:

System.InvalidOperationException: 不能有两个操作具有相同名称的相同合同,方法 SubmitDataAsync 和类型为 MyType 的 SubmitData 违反了此规则.您可以更改名称通过更改方法名称或使用OperationContractAttribute 的名称属性.

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

I can work around this by deleting the Async appended methods or simply using svcutil from VS2010. But I am wondering why svcutil generates an interface that causes a runtime exception (is this a bug?), and whether there is something additional I am supposed to do to make it work.

推荐答案

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

The default behaviour appears to have been changed. If you provide the /syncOnly parameter it preserved the old behaviour for me.

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

这篇关于.Net 4.5 Svcutil 生成两个同名操作(Method 和 MethodAsync)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 11:49