繁体   English   中英

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

[英]callback client not working in wcf wsdualhttpbinding

我有一个wcf双工服务和两个客户端。 场景是client1向wcf提交请求,并且wcf将其存储在DB.client2处理从DB接收的请求,并将状态发送给wcf服务,从而应将状态通知给client1。 client1的回调地址存储在一个静态变量中。client2通知wcf,但wcf不通知client1。 任何解决方案请。 提前致谢

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:

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:

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);
        }
    }

我没有为您的服务设置任何InstanceContextMode吗? 您应该设置“单一”以使您的应用按需运行。 否则,两个客户都会获得一项新服务。

为了进行调试,您可以将以下内容添加到服务中。 只是看看您的客户回叫渠道是否关闭或出现故障

    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