简体   繁体   English

回调客户端无法在wcf wsdualhttpbinding中工作

[英]callback client not working in wcf wsdualhttpbinding

i have one wcf duplex service and two clients. 我有一个wcf双工服务和两个客户端。 the scenario is that client1 submits requests to wcf and wcf stores it in DB.client2 processes the request taking it from DB and sends the status to wcf service which thereby should notify the client1 about the status. 场景是client1向wcf提交请求,并且wcf将其存储在DB.client2处理从DB接收的请求,并将状态发送给wcf服务,从而应将状态通知给client1。 the callback address of client1 is stored in a static variable.client2 notifies wcf but wcf doesnt notify client1. client1的回调地址存储在一个静态变量中。client2通知wcf,但wcf不通知client1。 Any solutions pls. 任何解决方案请。 Thanks in advance 提前致谢

service.cs: service.cs:

public class Service1 : IService1
    {
        static List<IServiceCallback> list = new List<IServiceCallback>();
        static IServiceCallback Callbck;

        public bool GetData(int value)
        {
            int i = 0;
            string s= string.Format("You entered: {0}", value);
            Callbck = OperationContext.Current.GetCallbackChannel<IServiceCallback>();

            i++;
            list.Add(Callbck);
            Ret("sss...");
            return true;
        }

        public  void Ret(string s)
        {

            foreach (var c in list)
            {

                Callbck.display(s);
                            }
        }

            }

client1.cs: client1.cs:

class Program
    {

        static void Main(string[] args)
        {
                                       InstanceContext instance = new InstanceContext(new Handler());
                Service1Client client = new Service1Client(instance);


                                bool res = client.GetData(123);

                if (res)
                    Console.WriteLine("true");


                    }
    }
    public class Handler :IService1Callback
    {
        public void display(string s)
        {
            Console.WriteLine(s);

        }


    }

client2.cs: client2.cs:

class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            i++;
                        Display();
        }

        public static void Display()
        {
            Console.WriteLine("hello");
            InstanceContext context = new InstanceContext(new Handlerss());
            Service1Client client = new Service1Client(context);

            client.Ret("done");


        }
    }

    class Handlerss : IService1Callback
    {
        public void display(string s)
        {
            Console.WriteLine(s);
        }
    }

i dont see any InstanceContextMode set for your service? 我没有为您的服务设置任何InstanceContextMode吗? you should set Single to get your app working like you want. 您应该设置“单一”以使您的应用按需运行。 otherwise both clients get a new service. 否则,两个客户都会获得一项新服务。

for debuging you can add the following to your service. 为了进行调试,您可以将以下内容添加到服务中。 just to see if your clientcallback channel closed or get faulted 只是看看您的客户回叫渠道是否关闭或出现故障

    public bool GetData(int value)
    {
        int i = 0;
        string s= string.Format("You entered: {0}", value);
        var callback= OperationContext.Current.GetCallbackChannel<IServiceCallback>();

        ICommunicationObject obj = (ICommunicationObject)callback;
        obj.Closed += SubscribedServiceClosed;//write log or console or something else 
        obj.Faulted += SubscribedServiceFaulted;//write log or console or something else

        i++;
        list.Add(callback);
        Ret("sss...");
        return true;
    }

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

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