WCF Service Contract issue...

Trying to create a very simple WCF service that can take in a Serializable object

and return a Serializable object. Here is the interface contract.

[ServiceContract()]

publicinterfaceISomeService

{

[OperationContract]

[ServiceKnownType(typeof(System.Data.DataSet))]

object Get(String Key);

[OperationContract]

[ServiceKnownType(typeof(System.Data.DataSet))]

void Set(String Key,object Object);

[OperationContract]

void Remove(String Key);

}

When I reference the contract in my client and call the Set method (passing a System.Data.DataSet object) I get:

There was an error while trying to serialize parameterhttp://tempuri.org/Surprisebject. The InnerException message was 'Type 'System.Data.DataSet' with data contract name 'DataSet:http://schemas.datacontract.org/2004/07/System.Data' 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.

Ultimately I want to pass more than just a DataSet object of course and had tried

adding the following to my config file for the client since doing it declaratively would

mean I'd have to recompile to define new objects:

<system.runtime.serialization>

<dataContractSerializer>

<declaredTypes>

<add type="System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

<knownType type="System.Data.DataSet, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

</add>

</declaredTypes>

</dataContractSerializer>

</system.runtime.serialization>

But I got the following error:
The value for the property 'type' is not valid. The error is: The type System.Object

cannot be used as a declared type in config.

What can I do to achieve this...please Help!

[3767 byte] By [DEKER] at [2008-1-8]
# 1

By any chance are you returning a typed dataset in your service implementation? If so, you will need to add it to the ServiceKnownType also as WCF client will not know how to deserialize them.

Hope this helps.

Thanks,

Sara

SaraWong-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2

Thanks Sara, but unfortunately that doesn't help. Here is the problem, I am trying to create a service contract for a caching service. The client needs to be able to arbitrarily pass any serializable type to the Set method. In the specific example it was a dataset but it could have been a string or some other object. I understand that the service contract needs to be aware of the type ahead of time so I tried to implement this using the config file where new types can be added as new clients come online and start to consume the service. But that didn’t work either. I’m beginning to feel like I must be crazy because this seems like it’s not unreasonable and should be pretty easy to do.Does this make sense to anyone but me. J I can pass strings into this service all day long but I try an object and it fails.

DEKER at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3

Can you send a repro to christian.weyer __AT__ thinktecture.com?

ChristianWeyer at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4

Hi Deker,

How are trying to implement this using config file?

If my understanding is correct, you don't know the type name/definition ahead of time. If so, you can provide a method to the ServiceKnownType attribute like the following (which is called only once per service):

[ServiceKnownType("MethodReturningDynamicType")]

where MethodReturningDynamicType should have the following signature:

Type[] MethodReturningDynamicType(ICustomAttributeProvider provider) { /* return all the types you know of*/}

Hope this helps.

Thanks,
Sara

SaraWong-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified