views:

1897

answers:

2

I am getting the error below when I call my WCF service. What am I missing here?

'System.String[]' with data contract name
'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays'
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.

{"There was an error while trying to serialize parameter
http://tempuri.org/:myEntity. The InnerException message was
'Type 'System.String[]' with data contract name
'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays'
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."}
+1  A: 

You haven't posted the code, so my answer is based on the assumption that you have a class myEntity which you are trying to serialize. Try using a KnownTypeAttribute for the class

e.g.

[KnownType(typeof(myEntity))]

You can refer to the following MSDN link: KnownTypeAttribute

Rashmi Pandit
thanks for ur answer....but it didnt work for me
Steve Chapman
Steve, can you please post a sample of your code?
Rashmi Pandit
+3  A: 

From what I gather, you have a WCF function that has a parameter named 'myEntity'. I'm assuming that the type of myEntity is a user-defined class and is adorned with the DataContract attribute, as it should be. I'm also assuming that the type of myEntity has a member field that is a string array. Let's assume that all of this is true (again, it'd be really helpful if you could post your code).

Ordinarily, string arrays, i.e., string[], will serialize just fine. But, in some cases (see here and here), you may have to add it to the list of known types in order for WCF to serialize everything correctly.

To do this, add the following:

[DataContract]
[KnownType(typeof(string[]))]
public class YourClassNameHere
{
}
Matt Davis
bang on target Matt...works like a charm!:-)thanks for ur answer!
Steve Chapman
Glad it worked for you.
Matt Davis