.Net 4.5 Svcutil generates two operations with the same name (Method and MethodAsync)

vossad01 picture vossad01 · Jul 18, 2012 · Viewed 9.3k times · Source

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.

Answer

Jimmy picture Jimmy · Nov 26, 2012

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.