15,559,819 members
See more:
I need to find a way to return a set of data in a WCF OperationContract. The data I am returning can be any rows and any number of columns.

My WCF (library) is hosted by a Windows Service. Thus far I get the usual error "Service cannot be started. System.NotSupportedException: Multi-dimensional arrays are not supported." I have tried jagged arrays, string[], DataSet, DataTable...any suggestions on how to return rows and columns of data?

FYI - Clearly I am new at WCF so please be gentle :-)

Here is some of my WCF Library code (some of it):

XML
[ServiceContract]
public interface IOperationsDataService
{
[OperationContract]
ReturnResults ExecuteStoredProcedure(string connectionKey, string procedureName, SpParameter[] spParameter, bool pleaseReturnRecords);
}

[DataContract]
public class ReturnResults
{
[DataMember]
public String[][] ReturnedResultsArray { get; set; }
}

*** Here is the entire error from the Event Viewer:

Service cannot be started. System.NotSupportedException: Multi-dimensional arrays are not supported.
at System.Runtime.Serialization.CollectionDataContract.CollectionDataContractCriticalHelper..ctor(Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.XsdDataContractExporter.GetSchemaTypeName(Type type)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.ValidateDataContractType(Type type)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreatePartInfo(MessagePartDescription part, OperationFormatStyle style, DataContractSerializerOperationBehavior serializerFactory)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreateMessageInfo(DataContractFormatAt...
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="HostedService" />
<EventID Qualifiers="0">0</EventID>
<Level>2</Level>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2013-01-04T18:52:14.000000000Z" />
<EventRecordID>4359</EventRecordID>
<Channel>Application</Channel>
<Computer>ntvdeva235.apsc.com</Computer>
<Security />
</System>
<EventData>
<Data>Service cannot be started. System.NotSupportedException: Multi-dimensional arrays are not supported.
at System.Runtime.Serialization.CollectionDataContract.CollectionDataContractCriticalHelper..ctor(Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.XsdDataContractExporter.GetSchemaTypeName(Type type)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.ValidateDataContractType(Type type)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreatePartInfo(MessagePartDescription part, OperationFormatStyle style, DataContractSerializerOperationBehavior serializerFactory)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreateMessageInfo(DataContractFormatAt...</Data>
</EventData>
</Event>
Posted
Updated 4-Jan-13 9:45am
v5

## Solution 1

1. Change the service starp account to that of a User with administrative privileges.

2.You can use Stream to return large data/Images.

3. Since you can't connect, it could be an access restriction, but this message can show when you've been kicked back for other issues, so this could be a missing referenced binary, or use of an invalid DataContract or something similar.

Firstly, turn on some diagnostics:

<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning, ActivityTracing" propagateActivity="true">
<listeners>
<filter type="" />
<filter type="" />
</listeners>
</source>
</sources>
<sharedListeners>
type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</sharedListeners>

Now run the service, get the error and using SvcTraceTool (just go to Program Files\Microsoft SDKs and do a search for svc) open up the output log. This will give you more of an overview of the process, at which point it goes wrong and point to more details of the exception - sometimes just telling you to look in the Event Log for the specific exception.

4.You will need to define something that is serializable. System.Drawing.Image is, but not in the cotnext of WCF (using DataContractSerializer) by default. That could range from returning the raw bytes as an array, or serialization to a string (base64, JSON) or implementing a DataContract that is serializable and can carry the data with it.

As others have said, WCF supports streaming, but that's not the crux of the issue here. Depending on the size of the data you might wish to do this, and doing so will reduce the problem in itself since you would be streaming bytes (from an evident, top-level view).