带回调的.net web服务调用

本文关键字:服务 调用 web net 回调 | 更新日期: 2023-09-27 18:11:04

是否有人知道如何发送各种"回调"参数到web服务,以便,当某个操作完成时,web服务可以调用回调,而无需从操作返回值。

例如,进度百分比,或者更类似于我的问题:

  • 你有3种水果(苹果、橙子和柠檬)
  • 您询问所有水果(3种水果)的信息

我希望web服务在知道每个水果的答案后立即返回每个值,但同时,保持在相同的动作调用中,所以我没有记录大量不同调用的问题(实际上,有超过3个水果),因为客户端与日志记录的某些方面进行交互,并且它可能非常令人困惑

 static void ClientFunction()
    {
        WebServiceFunction(Letters.All);
    }
    static bool WebServiceFunction(Letters whatLetters)
    {
        bool checkA = whatLetters == Letters.A, checkB = whatLetters == Letters.B, checkC = whatLetters = Letters.C,
            checkAll = whatLetters == Letters.All;
        //async wrapped
        if(checkA || checkAll)
        {
            // do something A
            // and send the answer to the client as soon as it is known
        }
        //async wrapped
        if (checkB || checkAll)
        {
            // do something B
            // and send the answer to the client as soon as it is known
        }
        //async wrapped
        if (checkC || checkAll)
        {
            // find out something about c
            // and send the answer to the client as soon as it is known
        }

        // lets say this is a generic return value ( for whatever the service does)
        return true;
    }
    enum Letters
    {
        A,
        B,
        C,
        All
    }

谢谢

带回调的.net web服务调用

查看WCF双工的内容

https://msdn.microsoft.com/en-us/library/ms731064 (v = vs.110) . aspx