【问题标题】:Why can't I generate a proxy with Tasks like add service reference does?为什么我不能像添加服务引用那样使用任务生成代理?
【发布时间】:2018-01-24 14:10:31
【问题描述】:

使用 Visual Studio 2017 15.5.4 (.NET 4.7.02053),我可以创建一个控制台应用程序,然后添加一个服务引用,该服务引用生成一个具有同步签名和基于任务的异步签名的代理。

[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 使用基于任务的签名生成轻量级代理的技巧是什么?

谢谢你, 斯蒂芬

【问题讨论】:

  • 尝试将 /async 移到 URL 前...
  • 你有没有把它绑起来,知道它有效,还是你在猜测?
  • 基本上是猜测,因为文档没有明确说明需要哪个顺序。

标签: c# wcf proxy


【解决方案1】:

通过阅读 Jon Skeet 的 comment 找到答案,然后推断出我需要的行为。

您不需要传递 /a 参数,这就是强制 IAsyncResult 模式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    相关资源
    最近更新 更多