简体   繁体   中英

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.

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.

// 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.

    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.

Under the Advanced menu there is an option to generate task based asynchronous methods.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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