I have a WFC(4.0) service dll for which I have to create a host application. The dll is pretty simple and has the following interfaces:
[ServiceContract(CallbackContract=typeof(IChatServiceCallback))]
public interface IService {
[OperationContract]
Guid Subscribe();
}
public interface IServiceCallback {
void NotifyClient(strign message);
}
My problem comes when I try to create a service. When I create a channel from the client to the host, I get the following exception: "The InstanceContext provided to the ChannelFactory contains a UserObjecct that does not implement the CallbackContractType 'Client.MyServiceReference.IServiceCallback'."
I found that in the ServiceReference object browser the ClientObject does not contain the IServiceCallback interface. Here my correspoding host code:
ServiceHost host = new ServiceHost(typeof(ChatService));
try
{
host.BeginOpen(new AsyncCallback(OnOpen), host);
mre.WaitOne();
if (host.State == CommunicationState.Opened)
{
Console.WriteLine("Server is running!\nServer listens on the following endpoints:");
foreach (var endp in host.Description.Endpoints)
{
Console.WriteLine("\t{0}", endp.Address);
}
Console.WriteLine("Press <Enter> to stop the server...");
Console.ReadLine();
host.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex.Message);
}
How can I create a host application for a Service dll which contains callback interface that is implemented on the client side?
ClientSide: try { clientID = client.Subscribe(); <-- Throws exception. } catch(Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK); }
Can you use the service contract assembly directly on the client? If so you can use DuplexChannelFactory and avoid the client-side service reference code altogether.
And example here
I know this doesn't answer your question but it may help you work around it.