开发者

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

开发者 https://www.devze.com 2023-03-25 03:33 出处:网络
This question already has an answer here: 开发者_开发百科 Closed 11 years ago. Possible 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

精彩评论

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