.NET 4.5 SvcUtil工具生成具有相同的名称(方法和MethodAsync)两个操作 [英] .Net 4.5 Svcutil generates two operations with the same name (Method and MethodAsync)

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

问题描述

我用消耗一个SvcUtil工具拉一个predefined 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没有问题lanuching该服务,
该SvcUtil工具程序,它是VS2012的一部分/ .net45还会生成一个方法,签名

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和
  SubmitData类型的MyType违反此规则。您可以更改名称
  通过改变方法名的操作中的一个的,或者使用
  名称OperationContractAttribute的属性。

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.

我可以通过删除异步附加方法或简单地使用SvcUtil工具VS2010从解决这一点。不过,我很奇怪,为什么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 的参数中,preserved旧的行为对我来说。

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工具生成具有相同的名称(方法和MethodAsync)两个操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆