Problem with DataTable in WCF DataContract

MHanke

Member
Joined
Jan 14, 2009
Messages
7
Programming Experience
Beginner
Hello,

I've got a little problem in my WCF Service and I haven't found an answer that could fix my problem yet.
In my ServiceContract a have declared a Function returning a DataTable, that works so far.
In my DataContract, I have a DataMember with the Type Object.
When this DataMember is a DataTable, and the Server returns this DataContract, the client throws an exception.

From my ServiceContract:

Public Interface IFormService

<OperationContract()> _
Function ListForms() As DataTable
....
------------

From my DataContract:

<DataContract()> _
Public Class ControlData

<DataMember()> _
Private oValue As Object
...
----------

When a DataTable is set to DataMember oValue, the Client throws the following exception:

An error occurred while receiving the HTTP response to
http://localhost:...
This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server
(possibly due to the service shutting down). See server logs for more details.

Inner Exception:
{"The underlying connection was closed: An unexpected error occurred on a
receive."}


I've found an article in the net, where they said, that the MaxReceivedSize and the ReaderQuotas should be enlarged, but this doesn't really help for me. That is really strange for me because it works in the ServiceContract, but not in my DataContract.
Does anyone know how I can fix or workaround this problem ?

My Configuration for the Service:

wsHttpBinding
SecurityMode.Message
Security.Transport.ClientCredentialType.Windows

Even if I change the type of oValue to DataTable, the Client throws the same exception...
 
Okay, now I have solved the problem with sending my DataTable as an Object.

But now on my clientside, the serialized DataTable is shown as an Array. How and where do I have to tell the serializer to deserialize this Type as a DataTable ?

The Array looks like:

- oValue {System.Array} Object
+ (0) "Attribute, Name="i:type", Value="b:DataTable"" System.Xml.XmlNode
+ (1) "Attribute, Name="xmlns:b", Value="http://schemas.datacontract.org/2004/07/System.Data"" System.Xml.XmlNode
+ (2) "Element, Name="xs:schema"" System.Xml.XmlNode
+ (3) "Element, Name="diffgr:diffgram"" System.Xml.XmlNode
 
Not sure why you need to use the DataContract. Can you just create a function that returns a Dataset?

In my DataContract I need an DataMember (Object) that can be several Datatypes. It is not a problem for the standard types like string, integer, boolean. These are values which I bind to controls on the clientside. Thats the problem in this case ...
 
I found that when returning a DataTable from a OperationContract I had to give the table a name, else it crashed.

With a OperationContract bound to a DataContract with a DataMember containing varying types you have to apply the KnownTypes attribute, see this article: Data Contract Known Types
A problem with this is that the generated proxy doesn't seem to pick these types up, adding the attribute here manually fixes it (until one update the proxy :().
 
Back
Top