Reputation: 6363
With Visual Studio 2017 15.5.4 (.NET 4.7.02053) I can create a console app, then add a service reference that produces a proxy with a synchronous signature and a Task based asynchronous signature.
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="urn:hpexstream-services/Engine", ConfigurationName="ServiceReference1.EngineWebService")]
public interface EngineWebService {
// CODEGEN: Parameter 'return' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
[System.ServiceModel.OperationContractAttribute(Action="urn:hpexstream-services/Engine:EngineWebService:ComposeRequest", ReplyAction="urn:hpexstream-services/Engine:EngineWebService:ComposeResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(ConsoleApp4.ServiceReference1.EngineServiceException), Action="urn:hpexstream-services/Engine:EngineWebService:Compose:Fault:EngineServiceExcept" +
"ion", Name="EngineServiceException")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
ConsoleApp4.ServiceReference1.ComposeResponse Compose(ConsoleApp4.ServiceReference1.ComposeRequest request);
[System.ServiceModel.OperationContractAttribute(Action="urn:hpexstream-services/Engine:EngineWebService:ComposeRequest", ReplyAction="urn:hpexstream-services/Engine:EngineWebService:ComposeResponse")]
System.Threading.Tasks.Task<ConsoleApp4.ServiceReference1.ComposeResponse> ComposeAsync(ConsoleApp4.ServiceReference1.ComposeRequest request);
}
But when I generate the same proxy with the Developer Command Prompt v15.5.4 and Svcutil.exe all I get back are the classic IAsyncResult based Begin and End methods. Here are various flavors of the command statement that I have tried:
D:\xyz>svcutil http://example.com/EngineService/EngineService?wsdl /async
D:\xyz>svcutil http://example.com/EngineService/EngineService?wsdl /async /tcv:Version35
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="urn:hpexstream-services/Engine", ConfigurationName="EngineWebService")]
public interface EngineWebService
{
// CODEGEN: Parameter 'return' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
[System.ServiceModel.OperationContractAttribute(Action="urn:hpexstream-services/Engine:EngineWebService:ComposeRequest", ReplyAction="urn:hpexstream-services/Engine:EngineWebService:ComposeResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(hpexstreamservices.Engine.EngineServiceException), Action="urn:hpexstream-services/Engine:EngineWebService:Compose:Fault:EngineServiceExcept" +
"ion", Name="EngineServiceException")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
ComposeResponse Compose(ComposeRequest request);
[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="urn:hpexstream-services/Engine:EngineWebService:ComposeRequest", ReplyAction="urn:hpexstream-services/Engine:EngineWebService:ComposeResponse")]
System.IAsyncResult BeginCompose(ComposeRequest request, System.AsyncCallback callback, object asyncState);
ComposeResponse EndCompose(System.IAsyncResult result);
}
What's the trick to forcing Svcutil to generate a lightweight proxy with Task based signatures?
Thank you, Stephen
Upvotes: 3
Views: 607
Reputation: 6363
Found the answer by reading a comment from Jon Skeet , then inferring the behavior I needed.
You don't need to pass the /a param, that's what forces the IAsyncResult Pattern.
Upvotes: 1