Which C# data types are not WCF serializable?

We have C# entity classes which map to some of our SQL Server database tables. We need to be able to serialize these classes in order to send them back to the client, from the server, via WCF. For each SQL Server data type, we have a corresponding C# CLR data type in the associated entity.

We have some SQL Server data types, such as Image and VarBinary that we need to map to a C# CLR data type, so we can pass the data back to the client. The problem is that I’m not sure what CLR data type to use for these Image and VarBinary SQL types, so that we can serialize them via WCF.

  • SQLDatareader via CLR not returning SQL Message right way
  • Same query, same DB, different execution plans & dramatically different times to execute
  • Most recent record in a left join
  • Syndication keys missing MVC
  • Struggling with a dynamic pivot on multiple columns with one being concatenated
  • How to search with multiple criteria from a database with SQL?
  • Thanks.

  • Easiest way to get a total count and a count of a subset?
  • Can a Linq query retrieve BLOBs from a Sql Database?
  • Passing SQL Server stored procedure parameter names via Delphi
  • Flattening Hierarchy series using SQL Server CTE
  • How to call a stored procedure from a user defined function In SQL Server 2000
  • Can I force SQL SMO to use READ UNCOMMITTED isolation?
  • 3 Solutions collect form web for “Which C# data types are not WCF serializable?”

    Types Supported by the Data Contract Serializer

    Data Contract Known Types

    Unless you use a binary transport, I expect that WCF is an extremely poor choice for sending binary because both SOAP and JSON are terrible at handling it. You could pass a byte[] array, for example, but that would be extremely verbose (especially in SOAP).

    Probably better to just BASE64 the data into a string and send that over.

    I think the links that Mitch included in his answer definitely help. The other thing to help you determine what CLR types to use would be what binding type are you going to use? If you use the NetXXX bindings (e.g. NetTcpBinding), you are assuming the client will be a .NET client, and the message encoding is optimized for that. You may be better off using a byte array for those types instead of a base64 string. If you’re going for interoperability (and using the WebHttpBinding or WSHttpBinding, or some other interoperable binding), then maybe the base64 string is the better way to go (as Kirk suggested). It won’t be optimized for speed/size, but you’re not depending on .NET being on the client.

    Hope this helps!

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.