0

I'm using a third party framework which generates WCF services from a custom language. However, when using collection classes, this is the generated output:

namespace MyNameSpace
{
    using System;
    using System.ServiceModel;

    [MessageContract]
    public class FindSomethingResponse
    {
        [MessageBodyMember(Order=1)]
        public System.Collections.Generic.List<SomethingDC> response;
    }
}

This is fine, but causes some undesired results when consuming the service. This is the XSD which the above generates:

<FindSomethingResponse>
    <ArrayOfSomethingDC>
        <SomethingDC/>
        <SomethingDC/>
        <SomethingDC/>
        ...
    </ArrayOfSomethingDC>
</FindSomethingResponse

The "group node" is called ArrayOfSomethingDC, but I would rather have it called something more meaningful (eg. "Somethings").

As far as I've found is that I have to use the CollectionDataContract attribute to name the node. However, I'm in the position I can't really change the structure of the generated class (since it's done in the third party framework), but I can only edit the above method.

Is it possible in any way?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Jos
  • 123
  • 1
  • 1
  • 5

1 Answers1

0

Try it as below

   namespace MyNameSpace
    {
        using System;
        using System.ServiceModel;

        [CollectionDataContract(Name = "Somethings", ItemName = "SomethingDC")]
        public class CustomList<T> : List<T>
        {
            public CustomList()
                : base()
            {
            }

            public CustomList(T[] items)
                : base()
            {
                foreach (T item in items)
                {
                    Add(item);
                }
            }
        }


        [MessageContract]
        public class FindSomethingResponse
        {
            [MessageBodyMember(Order = 1)]
            public CustomList<SomethingDC> response;
        }
    }
Cinchoo
  • 6,088
  • 2
  • 19
  • 34