Simon P
Simon P

Reputation: 1216

Send a List<string> to a wcf service

I've tried to look everywhere to find an answer to this problem, but no luck.. so i've turned to the experts here for some help!

I have a wcf service in c# is fully working... it does some magic and it sends a List to the server. The server can read these PO objects fine. However, i now have a problem when inside PO there is a list...

public class PO
{
    /* omitted */
    [DataMember]
    public Object BasicContent { get; set; }
}

When BasicContent is a List i get the following error:

"There was an error while trying to serialize parameter http://tempuri.org/:objectToPersist. 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."

I have tried adding [ServiceKnownType(typeof(List<string>))] or [ServiceKnownType(typeof(string[]))] all over the place by no avail...

Can anyone give me a hand on what I can do?

Upvotes: 0

Views: 2678

Answers (2)

dkarzon
dkarzon

Reputation: 8038

Have you tried changing the type to String or String[] or List depending on what your setting it to.

Upvotes: 1

JaredPar
JaredPar

Reputation: 754595

Try adding a ServiceKnownType for just String

[ServiceKnownType(typeof(string))]

Upvotes: 0

Related Questions