tags:

views:

150

answers:

0

Hello,

I am trying to pass a DetachedCriteria of NHibernate to a WCF Service. I get a strange error, I think it is something WCF specific. I solved the actual problem by "manually" serializing the class (see code). But I would like to know how to solve the real problem, that the second function runs..

The error message is:

There was an error while trying to serialize parameter http://tempuri.org/%3Ac. The InnerException message was 'Type 'System.RuntimeType' with data contract name 'RuntimeType:http://schemas.datacontract.org/2004/07/System' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

The code for the DataContract is:

 [ServiceContract]

[ServiceKnownType(typeof(CriteriaImpl))]

public interface INHibernateQueryService
{
    [OperationContract]
    IList<FileSystemEvArgs> QueryDatabaseA(byte[] c);

    [OperationContract]
    IList<FileSystemEvArgs> QueryDatabaseB(DetachedCriteria c);

    [OperationContract]
    DateTime GetCurrenTime();
}

The client code is:

var criteria = DetachedCriteria.For<FileSystemEvArgs>().SetMaxResults(100);

// Convert the DetachedCriteria to a byte array
var ms = new MemoryStream();
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(ms, criteria);

foreach (var e in _client.Proxy.QueryDatabaseA(ms.GetBuffer()))
Debug.WriteLine(e.Fullpath);

foreach (var e in _client.Proxy.QueryDatabaseB(criteria))
    Debug.WriteLine(e.Fullpath);

The first function (QueryDatabaseA) works perfectly. The second throws. Thanks for any tips..

Chris

Btw: I think it is not "really" related to NHibernate, more a genera WCF question. But nonetheless, perhaps somebody knows how to solve it...