Reputation: 10758
Im trying to consume a WCF service in silverlight...
What I have done is to create two seperate assemblies for my datacontracts...
Assembly that contains all of my types marked with data contracts build against .Net 3.5
A Silverlight assembly which links to files in the 1st assembly.
This means my .Net app can reference assembly 1 and my silverlight app assembly 2. This works fine and I can communicate across the service.
The problems occur when I try to transfer inherited classed. I have the following class stucture...
IFlight - an interface for all types of flights.
BaseFlight : IFlight - a baseflight flight implements IFlight
AdhocFlight : BaseFlight, IFlight - an adhoc flight inherits from baseflight and also implements IFlight.
I can successfully transfer base flights across the service. However I really need to be able to transfer objects of IFlight across the interface as I want one operation contract that can transfer many types of flight...
public IFlight GetFlightBooking()
{
AdhocFlight af = new AdhocFlight();
return af;
}
... should work I think?
However I get the error:
"The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."
Any ideas would be appreciated.
Upvotes: 1
Views: 1057
Reputation: 2634
This may or may not be related to a bug with serializing generic interface types in WCF as logged here.
If this is related to your problem you'll be glad to hear that it's fixed in .net 4.0
Upvotes: 0
Reputation: 1062502
You say that BaseFlight
works; does your base-class name the known types?
[DataContract]
[KnownType(typeof(AdhocFlight))]
class BaseFlight : IFlight {...}
You might also want to look at [ServiceKnownType]
. In general, WCF isn't going to like the interface-based approach (IFlight
), as it is going to want to know exactly what to expect from the data it is (de)serializing; I would expect it to work fine with the above and using BaseFlight
on the API.
Upvotes: 4
Reputation: 4328
I think what you want to do is possible in "normal" .NET WCF. Here is a question that talks about passing interfaces in a WCF service:
Passing Interface in a WCF Service?
But I seriously doubt whether this will work in Silverlight. WCF support in SL is sketchy, to say the least. I haven't tried it though. I might be wrong.
Upvotes: 1