gpt4 book ai didi

c# - 为什么我不能像添加服务引用那样使用任务生成代理?

转载 作者:行者123 更新时间:2023-11-30 17:31:06 26 4
gpt4 key购买 nike

借助 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/异步

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

谢谢,斯蒂芬

最佳答案

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

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

关于c# - 为什么我不能像添加服务引用那样使用任务生成代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48424486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com