使用Visual Studio 2017 15.5.4 (.NET 4.7.02053),我可以创建一个控制台应用程序,然后添加一个服务引用,生成一个带有同步签名和基于Task的异步签名的代理。
[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);
}
然而当我使用 Developer Command Prompt v15.5.4 和 Svcutil.exe 生成相同的代理时,我只得到了基于经典 IAsyncResult 的 Begin 和 End 方法。这里是我尝试过的各种命令语句:
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);
}
如何强制Svcutil生成具有基于任务的签名的轻量级代理?
谢谢, Stephen