15

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 )

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 );

This causes a run-time exception:

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.

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.

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
vossad01
  • 11,552
  • 8
  • 56
  • 109

1 Answers1

21

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.
Jimmy
  • 823
  • 9
  • 12
  • Thanks, @Jimmy, but I know the behavior has changed (see question). I also know about the `/syncOnly` flag (see my comment to the question). I am curious about why the behavior changed. The best I have is that the new interface is desirable for clients though not valid for servers. – vossad01 Nov 27 '12 at 21:32
  • 1
    The other thing that puzzled me while I was searching for a solution to this was that the information on the WWW indicated that this is because of overloaded methods and the problem can be solved by giving the methods distinct OperationContract names, but clearly 'Method' and 'MethodAsync' are not overloaded methods, so somehow, the generated code or VS interprets it to have the same OperationContract names. – methon.dagger Oct 19 '14 at 02:21