views:

23

answers:

1

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.

+1  A: 

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
{
  ....
}
onof
Thanks for your reply. Could you share some code samples as I'm relativly new to both WCF as well as Ajax?
Konrad
i edited my answer
onof