开发者

Which C# data types are not WCF serializable?

We have C# entity classes which map to some of our SQL Server databa开发者_Go百科se 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.

Thanks.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜