none
How to include Task-based operation in Nuget package of WCF service RRS feed

  • Question

  • I have requirement to create Nuget package of WCF service project which should include task-based operation in nuget package while creating.

    WCF service is built in .Net framework 4.7.2.

    I have created Nuget package of WCF service library which includes all method of WCF service but how to include task-based operation in package?

    For example: My WCF service has only one method name: GetData() Nuget package created with WCF service includes GetData() method which is fine.

    When we add service reference in client project it will add two methods 1. GetData() 2. GetDataAsync() (Task-based operation method)

    I want to include GetDataAsync() method in my Nuget package while creation.

    Used:

    .Net Framework - 4.7.2

    VS 2019

    Friday, July 5, 2019 9:05 AM

All replies

  • Hi VP309,
    What does “I have created Nuget package of WCF service library which includes all method of WCF service” mean?
    Do you create the WCF service library by using Nuget package? However, the asynchronous method is a programmatic model on the client side (the method is generated by the option of task-based or asynchoronous method).
    We could also return the Task<T> method on the server side.
           [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            Task UploadStream(Stream stream);

    Alternatively, the project you created is a WCF client, you want to add task-based operation method, do you?
    Best Regards
    Abraham
    Friday, July 5, 2019 10:00 AM
    Moderator
  • Hello Abraham,

    I have WCF service project created which contains more than 80 methods. 

    On client side we have added WCF reference using right click "Add service reference" option. while adding reference option "Generate task-based operation" is checked which will automatically creating async methods.

    Now, here we need to create nuget package of our WCF service project which should contain all methods of my WCF project plus is there any way using which we can create task-based operation as well in nuget package. we don't want to update our WCF service project.

    So once nuget package is created we will add it into client and will remove "Add service reference" option from client.

    Thanks.

    Monday, July 8, 2019 5:42 AM
  • Hi, 
    Namely, your nugget package exists as a WCF client, right? It exposes WCF methods for reference by other projects so that WCF services can be invoked.
    If it indeed, I think we might encapsulate these methods with using ChannelFactory<T>, then call the WCF service by using these methods.
    As you know, there are two ways to call the service generally.
    1. Use the client proxy class
    2. Use the ChannelFactory<T> 
    Please refer to the below document.
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
    Best Regards
    Abraham
    Monday, July 8, 2019 9:54 AM
    Moderator
  • Hello Abraham,

    i refer document link shared by you but how can i call async method of WCF service which are generated automatically while adding service reference in project.

    Lets say my WCF project "WCFService" has method "Add()".

    i have client project "WCFClient". i am adding service reference of my "WCFService" project into my client project using "Add Service Reference" and "Generate task-based operation" is checked.

    After adding reference, if i will create proxy object of my service

    ServiceReference.IService servObj = new ServiceReference.ServiceClient();
    servObj .Add();

    servObj .AddAsync();   -- This method is automatically created while adding service reference into client project.

    So i am unable to achieve async method creation while creating nuget package of my "WCFService" project. I am able to access only "Add()" method. 

    How can we add/access "AddAsync()" method thorugh nuget package. I need to include "AddAsync()" in my nuget package automatically.

    Thanks.

    Monday, July 8, 2019 10:26 AM
  • Hi,
    The key is how you create the Nuget Package. 
    I mean that if your Nuget package project is a client project, which is used to call the service. We could create an asynchronous method you want by encapsulating the invocation with ChannelFactory<T>.
    [quote] “I need to include "AddAsync()" in my nuget package automatically.” [/quote]
    I don’t think there are some simple ways could attain this.
    Best Regards
    Abraham

    Tuesday, July 9, 2019 6:22 AM
    Moderator