我有一個wcf雙工服務和兩個客戶端。情景是,client1向wcf提交請求,wcf將請求存儲在DB.client2中處理從DB獲取的請求,並將狀態發送到wcf服務,從而通知客戶端1狀態。 client1的回調地址存儲在一個靜態變量中.client2通知wcf,但wcf不通知client1。任何解決方案,請。 在此先感謝回調客戶端不工作在wcf wsdualhttpbinding
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);
}
}
沒有包括我保存到Db的真實場景。遇到與此示例相同的概率因此發佈此代碼 – sow 2012-01-31 10:47:06
這些運行在同一臺機器上或不同的機器上? – 2012-02-01 08:57:49
yes.both即使在設置instancecontextmode = single之後也在同一臺機器上 – sow 2012-02-01 14:30:13