开发者

How to rename xml root in WCF response? [duplicate]

This question already has an answer here: 开发者_开发百科 Closed 11 years ago.

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 :(


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; }
...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜