I have already configured my Service Reference and set my collection to Generic.List .
When i fill the List<Objects>
with a string or int, it works fine. But when I fill it with a List<String>
, it gives a runtime-error while trying to serialize parameter
So is there a way to pass a List<Objects>
that contains several List<String>
to WCF?
Use the KnownType attribute on your data contract. See Data Contract Known Types.
Did you try passing the list as a "List of List of String" instead of "List of Objects"? Maybe SOAP lacks the serialization INFO when you pass the list as object....
then pass the "allYourStringLists" object
I think you'll need to pass an array of objects, rather than trying to use a generic. Web services are platform agnostic so need to be consumed by potentially any client - what if a .NET 1.x applicaton tried to access the service?
Hmm... so you want to pass a list of list of strings. correct?
why not doing this then?
Using the XmlSerializer Class:
Windows Communication Foundation (WCF) can use two different serialization technologies to turn the data in your application into XML that is transmitted between clients and services, a process called serialization.
DataContractSerializer as the Default:
By default WCF uses the DataContractSerializer class to serialize data types. This serializer supports the following types: Primitive types (for example, integers, strings, and byte arrays), as well as some special types, such as XmlElement and DateTime, which are treated as primitives.
Data contract types (types marked with the DataContractAttribute attribute).
Types marked with the SerializableAttribute attribute, which include types that implement the ISerializable interface.
Types that implement the IXmlSerializable interface.
Many common collection types, which include many generic collection types.
Many .NET Framework types fall into the latter two categories and are thus serializable. Arrays of serializable types are also serializable. For a complete list, see Specifying Data Transfer in Service Contracts. The DataContractSerializer, used together with data contract types, is the recommended way to write new WCF services. For more information, see Using Data Contracts.
When to Use the XmlSerializer Class:
WCF also supports the XmlSerializer class. The XmlSerializer class is not unique to WCF. It is the same serialization engine that ASP.NET Web services use. The XmlSerializer class supports a much narrower set of types than the DataContractSerializer class, but allows much more control over the resulting XML and supports much more of the XML Schema definition language (XSD) standard. It also does not require any declarative attributes on the serializable types. For more information, see the XML Serialization topic in the .NET Framework documentation. The XmlSerializer class does not support data contract types. When using Svcutil.exe or the Add Service Reference feature in Visual Studio to generate client code for a third-party service, or to access a third-party schema, an appropriate serializer is automatically selected for you. If the schema is not compatible with the DataContractSerializer, the XmlSerializer is selected.
Manually Switching to the XmlSerializer:
At times, you may have to manually switch to the XmlSerializer. This happens, for example, in the following cases: When migrating an application from ASP.NET Web services to WCF, you may want to reuse existing, XmlSerializer-compatible types instead of creating new data contract types.
When precise control over the XML that appears in messages is important, but a Web Services Description Language (WSDL) document is not available, for example, when creating a service with types that have to comply to a certain standardized, published schema that is not compatible with the DataContractSerializer.
When creating services that follow the legacy SOAP Encoding standard.
In these and other cases, you can manually switch to the XmlSerializer class by applying the XmlSerializerFormatAttribute attribute to your service, as shown in the following code.
I've had the same problem passing generic lists in a WCF Service. The reason for this is that by default
DataContractSerializer
is used to serialize the data. Using theXmlSerializer
solved the problem for me.more info: http://msdn.microsoft.com/en-us/library/ms733901.aspx