开发者

Asp.Net Ajax Control using WCF service with CallbackContract

Is it possible to use WCF's CallbackContract or any other "remote eventing" mechanism provided by WCF from an Asp.Net Ajax control/page?

So far all the articles I found treated separately about CallbackContracts and WCF's usage from Asp.Net pages. Is there any way to make the service's callback reach back to the page that开发者_运维知识库 initiated the call?

Thanks a lot in advance.


Yes, of course. If you want just to call a wcf service with a callback (Duplex) you can do it as usual in the script method.

Edit: I don't know what you have to do with Ajax, but, suppose that you want to suggest the user to fill a textbox with an AutoCompleteExtender using data coming from a WCF service, you have to provide a ScriptMethod. Inside it you can call the service in the usual way as explained in MSDN

[WebMethod, ScriptMethod]
public static string[] GetSuggestedItems(string prefixText, int count)
{
  // Construct InstanceContext to handle messages on callback interface
  InstanceContext instanceContext = new InstanceContext(new MyCallbackHandler());

  // Create a client
  MyDuplexClient client = new MyDuplexClient(instanceContext);

  return client.GetModelItems(prefixText).GetRange(0, count);
}

once you have defined callback handler:

public class MyCallbackHandler : IMyCallbackContract
{
  ....
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜