views:

313

answers:

3

Hi,

Im trying to consume a WCF service in silverlight...

What I have done is to create two seperate assemblies for my datacontracts...

  1. Assembly that contains all of my types marked with data contracts build against .Net 3.5

  2. 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.

+1  A: 

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:
http://stackoverflow.com/questions/310160/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.

Henrik Söderlund
Hi, Im happy to announce it does work :) I attributed my service as follows: [ServiceKnownType(typeof(Flight))] [ServiceKnownType(typeof(FlightLiveOps))] [ServiceKnownType(typeof(FlightScheduled))] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class DispatchService
RemotecUk
+4  A: 

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.

Marc Gravell
[ServiceKnownType] was the key - I added it to the service contract.
RemotecUk
A: 

This may or may not be related to a bug with serializing generic interface types in WCF as logged here.

http://connect.microsoft.com/VisualStudio/feedback/details/391260/executionengineexception-thrown-from-datacontractserializer-with-ilist-t

If this is related to your problem you'll be glad to hear that it's fixed in .net 4.0

Ciaran