none
WCF Serializa Collection ListItemCollection C# RRS feed

  • Question

  • I am new in WCF

    I wants to serialize SharePoint ListItemCollection (it is of table format)

     [DataContract]
        public class MyCollectionClass
        {
            private ListItemCollection itemColl;
            [DataMember]
            public ListItemCollection ItemColl
            {
                get;
                set;
            }
        }
    
    Interface
    
    [OperationContract]
            List<MyCollectionClass> TestListType(string listName);
    
    Then get Items in variable listItems and returning.
    
    List<MyCollectionClass> c = new List<MyCollectionClass>();
                        c.Add(new MyCollectionClass() { ItemColl= listItems });
                        return c;
    

    While adding service getting error

    An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true,

    whose value is:System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension:

    System.ServiceModel.Description.DataContractSerializerOperationBehavior contract:

    http://tempuri.org/:IGetCost ----> System.Runtime.Serialization.InvalidDataContractException:

    Type 'Microsoft.SharePoint.Client.ListItemCollection'

    cannot be serialized. Consider marking it with the DataContractAttribute attribute,

    and marking all of its members you want serialized with the DataMemberAttribute attribute.

    If the type is a collection, consider marking it with the CollectionDataContractAttribute.

    See the Microsoft .NET Framework documentation for other supported types.

    at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, 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.DataContractSet.GetDataContract(Type clrType)

    at System.Runtime.Serialization.DataContractSet.GetMemberTypeDataContract(DataMember dataMember)

    at System.Runtime.Serialization.DataContractSet.AddClassDataContract(ClassDataContract classDataContract)

    at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)

    at System.Runtime.Serialization.DataContractSet.AddCollectionDataContract(CollectionDataContract collectionDataContract)

    at System.Runtime.Serialization.DataContractSet.InternalAdd(XmlQualifiedName name, DataContract dataContract)

    at System.Runtime.Serialization.DataContractSet.Add(Type type) at System.Runtime.Serialization.XsdDataContractExporter.Export(Type type)

    at System.ServiceModel.Description.MessageContractExporter.ExportType(Type type, String partName, String operationName, XmlSchemaType& xsdType)

    at System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32 messageIndex, Object state)

    at System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32 messageIndex, Object state)

    at System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()

    at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext)

    at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension) --- End of inner ExceptionDetail stack trace ---

    at System.ServiceModel.Description.ServiceMetadataBehavior.MetadataExtensionInitializer.GenerateMetadata() at System.ServiceModel.Description.ServiceMetadataExtension.EnsureInitialized()

    at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.InitializationData.InitializeFrom(ServiceMetadataExtension extension) at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.GetInitData()

    at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.TryHandleDocumentationRequest(Message httpGetRequest, String[] queries, Message& replyMessage)

    at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.ProcessHttpRequest(Message httpGetRequest) at System.ServiceModel.Description.ServiceMetadataExtension.HttpGetImpl.Get(Message message)

    at SyncInvokeGet(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)

    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)

    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)

    at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)

    at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

    Any help much appreciated.

    Wednesday, December 25, 2013 9:56 AM

Answers

  • Hi,

    >>Type 'Microsoft.SharePoint.Client.ListItemCollection' cannot be serialized. Consider marking it with the DataContractAttribute attribute,and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types. 

    As the error said, maybe you can try to customize collection types by using the CollectionDataContractAttribute attribute.

    For more information, please try to refer to:
    #Collection Types in Data Contracts:
    http://msdn.microsoft.com/en-us/library/aa347850(v=vs.110).aspx .

    Best Regards,
    Amy Peng



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 26, 2013 5:39 AM
    Moderator

All replies

  • for now I have created 3D jagged array of type string to serialize table.

    <a:ArrayOfArrayOfstring>
              <a:ArrayOfstring>
                <a:string>ID</a:string>
                <a:string>1</a:string>
              </a:ArrayOfstring>
              <a:ArrayOfstring>
                <a:string>ContentTypeId</a:string>
                <a:string>0xF97</a:string>
              </a:ArrayOfstring>
              <a:ArrayOfstring>
                <a:string>Title</a:string>
                <a:string>TestTitle</a:string>
    .
    .
    </a:ArrayOfArrayOfstring>
    .
    

    But I want this like

    <a:Item>
              <a:ID>1</a:ID>
              <a:ContentTypeId>0xF97</a:ContentTypeId>
              <a:Title>TestTitle</a:Title>
    </a:Item>
    .
    .

    any Idea or reference are welcome.

    Wednesday, December 25, 2013 1:44 PM
  • Hi,

    >>Type 'Microsoft.SharePoint.Client.ListItemCollection' cannot be serialized. Consider marking it with the DataContractAttribute attribute,and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types. 

    As the error said, maybe you can try to customize collection types by using the CollectionDataContractAttribute attribute.

    For more information, please try to refer to:
    #Collection Types in Data Contracts:
    http://msdn.microsoft.com/en-us/library/aa347850(v=vs.110).aspx .

    Best Regards,
    Amy Peng



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 26, 2013 5:39 AM
    Moderator