简体   繁体   English

Visual Studio WSDL创建异步/等待SOAP Web服务

[英]Visual Studio WSDL create async/await SOAP webservice

I've got a SOAP webservice in my C# winforms application, but I'm trying to get WSDL.exe to generate with Task-Based async/await methods. 我的C#winforms应用程序中有一个SOAP Web服务,但是我试图使WSDL.exe与基于任务的异步/等待方法一起生成。

I've read up on the documentation here and tried adding the following XML file into the par switch but its still not giving me the awaitable Task based methods for calling the webservice methods asynchronously. 我已经阅读了这里的文档并尝试将以下XML文件添加到par开关中,但是它仍然没有给我等待的基于任务的异步调用Webservice方法的方法。

// BEGIN WSDLPARAMETERS.XML

<wsdlParameters  xmlns="http://microsoft.com/webReference/">
  <webReferenceOptions>
    <verbose>false</verbose>
    <codeGenerationOptions>properties newAsync enableDataBinding</codeGenerationOptions>
  </webReferenceOptions>
</wsdlParameters>

// END WSDLPARAMETERS.XML

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>wsdl.exe  "http://********/interchangeservices.asmx" /out:"****\WebServices.cs" /l:CS  /n:"AdelaideInterchangeAutomation" /par:"*****\wsdlparameters.xml"

this returns methods like this 这将返回这样的方法

    /// <remarks/>

    public AwaitingUpload CheckHistoryNotUploaded() {
        object[] results = this.Invoke("CheckHistoryNotUploaded", new object[0]);
        return ((AwaitingUpload)(results[0]));
    }

    /// <remarks/>
    public void CheckHistoryNotUploadedAsync() {
        this.CheckHistoryNotUploadedAsync(null);
    }

    /// <remarks/>
    public void CheckHistoryNotUploadedAsync(object userState) {
        if ((this.CheckHistoryNotUploadedOperationCompleted == null)) {
            this.CheckHistoryNotUploadedOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCheckHistoryNotUploadedOperationCompleted);
        }
        this.InvokeAsync("CheckHistoryNotUploaded", new object[0], this.CheckHistoryNotUploadedOperationCompleted, userState);
    }

    private void OnCheckHistoryNotUploadedOperationCompleted(object arg) {
        if ((this.CheckHistoryNotUploadedCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.CheckHistoryNotUploadedCompleted(this, new CheckHistoryNotUploadedCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }

but ideally I would like it to return Task-Based async methods so i can call them with the await keyword. 但理想情况下,我希望它返回基于任务的异步方法,以便我可以使用await关键字调用它们。

    public AwaitingUpload CheckHistoryNotUploaded() {
        object[] results = this.Invoke("CheckHistoryNotUploaded", new object[0]);
        return ((AwaitingUpload)(results[0]));
    }

    /// <remarks/>
    public async Task<AwaitingUpload> CheckHistoryNotUploadedAsync() {
        await .....
    }

I was able to solve this by creating the file via Add Connected Service in Visual Studio. 我可以通过在Visual Studio中通过“ Add Connected Service创建文件来解决此问题。

Under the Advanced menu there is an option to generate task based asynchronous methods. 在“ Advanced菜单下,有一个选项可以生成基于任务的异步方法。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM