3

Possible Duplicate:
WCF REST: remove prefix “ArrayOf” for wcf method response

I have defined a simple WCF service in c# like this:

[ServiceContract]
public interface IAugeService
{
    [OperationContract]
    [WebGet]
    List<Face> DetectedFaces();
}

I can create an endpoint with WebHttpBinding and most of it works just fine. But the name for the root element in the generated xml response is derived from the return type, so I get something like this:

<ArrayOfFace>
    <Face>
        ...
    </Face
    ...
</ArrayOfFace

I need to give the root node a different name.

I tried to change the method declaration to this:

...  
[OperationContract]
[WebGet]
[return: MessageParameter(Name="result")]
List<Face> DetectedFaces();
...

... but it didn't help :(

Community
  • 1
  • 1
sne11ius
  • 726
  • 1
  • 9
  • 18
  • Someone else already had the same problem: [How can I control the name of generic WCF return types?](http://stackoverflow.com/questions/172265/) – Filburt Aug 03 '11 at 12:25
  • 1
    There is nothing in that thread that solves my problem. – sne11ius Aug 03 '11 at 12:31

1 Answers1

0

Add Name attribute to your DataMember. It will add an extra tag, though.

[DataContract(Name = "FaceList")
public class FaceList
{
...
[DataMember(Name = "Result")]
List<Face> Faces { get; set; }
...
}
fozylet
  • 1,279
  • 1
  • 13
  • 25