tags:

views:

129

answers:

2

I have a WCF service. I can return a concrete class without a problem, but returning a reference to an interface causes the following issue.

CommunicationException occurred "The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.2030000'."

This occurs when I try to get an instance of a class from a WCF service:

//create the connection
ChannelFactory<IService> _ChannelFactory = new ChannelFactory<IService>(_EndpointName);
IService _ServiceProxy = _ChannelFactory.CreateChannel();

//communication exception thrown here
ITestInterface okcomputer = _ServiceProxy.GetTest();

IService and ITestInterface have all the normal OperationContract attributes and such. The Service has the attribute: [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

other than that, the classes and interfaces are nothing special.

I feel like there is some special trick to returning a class interface from a WCF interface, otherwise I wouldn't be having this problem.. What's the trick?

+1  A: 

You cannot return an interface, ever. How would it be serialized?

Interfaces are about behavior. Behavior is not serialized, only data.

John Saunders
Damn! It can't be!
MedicineMan
Can too! What's the XML Schema definition of your interface? What's the WSDL look like? It's web services, so is this interface a service contract? If so, it has operations. How do you serialize an operation?
John Saunders
during development time, I designed this with the option of swapping out stubbed out versions for debugging. Can I achieve the same functionality if I replace the references to interfaces with references to abstract base classes or base class and subclass combinations?
MedicineMan
You need a concrete class. It's the schema of the concrete class that will be seen by the clients.
John Saunders
True Service-oriented programming is quite a different beast from OO-programming! You need to "unlearn" certain principles again.....
marc_s
damn, I put so much effort into learning OO best practices too. This really screws me up.
MedicineMan
Who ever told you that web services were OO? And I'd just as well break it to you now, to prevent future disappointment: XML is not OO, either.
John Saunders
A: 

John is right you want to return an instance of a class that implements the interface. But from the exception it looks like simply attempting to return the interface is not your problem. Have you tried digging down into the inner exceptions if they're any?

SpaceghostAli