为什么我无法使用添加服务引用等任务生成代理?

时间:2018-01-24 14:10:32

标签: c# wcf proxy

使用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&gt; svcutil http://example.com/EngineService/EngineService?wsdl / async

D:\ xyz&gt; 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使用基于任务的签名生成轻量级代理的技巧是什么?

谢谢你, 斯蒂芬

1 个答案:

答案 0 :(得分:1)

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

你不需要传递/ a param,这就是强迫它的原因 IAsyncResult模式。