server client architecture. No IIS involved. Both applications are WinForm!
I’ve made the following interfaces in a shared Library:
[ServiceContract(SessionMode=SessionMode.Required,
CallbackContract=typeof(ClientInterface))]
public interface RequestInterface
{
[OperationContract]
void Subscribe();
[OperationContract]
MyInterface GetInterface();
}
public interface MyInterface
{
[DataMember]
List<MySubInterface> SubClasses{get;}
}
public interface MySubInterface
{
[DataMember]
int Value { get; }
}
And implemented them on the server like this:
public class RequestHandler : RequestInterface
{
private List<ClientInterface> iClients = new List<ClientInterface>();
public MyInterface GetInterface()
{
List<MySubInterface> tList = new List<MySubInterface>();
Form1.AddText("method invoked by:" + Thread.CurrentContext.ToString());
foreach (RealSubclass tClass in Form1.iClass.SubClasses)
{
tList.Add(new TransmissionSubclass(tClass.Value));
}
TransmissionClass tTC = new TransmissionClass(tList);
Form1.AddText("created:" + tTC);
return tTC;
}
public void Subscribe()
{
Form1.AddText("subscribing:" + OperationContext.Current.GetCallbackChannel<ClientInterface>());
iClients.Add(OperationContext.Current.GetCallbackChannel<ClientInterface>());
fireClassEvent("halloWelt");
}
}
On the client I’m doing the following piece of code, trying to invoke the GetInterface() method:
ClientClass tClass = new ClientClass(this);
DuplexChannelFactory<RequestInterface> pipeFactory =
new DuplexChannelFactory<RequestInterface>(
tClass,
new NetNamedPipeBinding(),
new EndpointAddress(
"net.pipe://localhost/Request"));
RequestInterface pipeProxy = pipeFactory.CreateChannel();
//pipeProxy.Subscribe(); -- works like a charm
MyInterface tInterface = pipeProxy.GetInterface(); // doesn't work
fillListView(tInterface);
However, when debugging through the client step by step the debugging breaks at the marked line and seems to exit this function.
It only returns to ‘step by step’ mode when I close the application’s form.
On the other hand I can see from logging output on my server, that the GetInterface() method gets executed.
The TransmissionClass and TransmissionSubclass are both in the shared library and implement MyInterface / MySubInterface
[DataContract]
[Serializable]
public class TransmissionClass : MyInterface
{
[DataMember]
public List<MySubInterface> SubClasses{get;private set;}
public TransmissionClass(List<MySubInterface> aList)
{
SubClasses = aList;
}
public override string ToString()
{
return "TransmissionClass,Count:" + SubClasses.Count;
}
}
WCF-initialization on the server side:
using (ServiceHost host = new ServiceHost(
typeof(RequestHandler),
new Uri[] { new Uri("net.pipe://localhost") }))
{
ServiceDebugBehavior tBehavior = new ServiceDebugBehavior();
if (null == tBehavior)
{
host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
}
else if (!tBehavior.IncludeExceptionDetailInFaults)
{
tBehavior.IncludeExceptionDetailInFaults = true;
}
host.AddServiceEndpoint(typeof(RequestInterface),
new NetNamedPipeBinding(), "Request");
host.Open();
Application.Run(new Form1());
host.Close();
}
Put the [KnownTypes] attribute to let WCF to know what concrete classes implements your interface.