i have one wcf duplex service and two clients. 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. the callback address of client1 is stored in a static variable.client2 notifies wcf but wcf doesnt notify client1. Any solutions pls. Thanks in advance
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);
}
}
i dont see any InstanceContextMode set for your service? 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;
}
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.