我正在使用 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/