当返回类型为 wcf 宁静服务中的泛型类型时,如何删除 xml 命名空间 [英] How to remove xml namespace when return type is generic type in wcf restful service

查看:33
本文介绍了当返回类型为 wcf 宁静服务中的泛型类型时,如何删除 xml 命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是接口定义.

[OperationContract]
[WebGet(UriTemplate = "FacebookData/?accessToken={accessToken}")]
OperationResult<FacebookData> GetFacebookData(string accessToken);

返回类型为OperationResult,是泛型类型

The return type is OperationResult<FacebookData>, it is a generic type

然后我会得到如下的 xml...

Then i will get xml like following...

OperationResultOfFacebookDataNcCATIYq xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

OperationResultOfFacebookDataNcCATIYq xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

如何删除命名空间并将 xml 元素重命名为OperationResult"

How can I remove namespace and rename xml element as "OperationResult"

顺便说一下,我已经设置了Namespace is empty

By the way, I already set Namespace is empty

[DataContract(Namespace = "")]
public class OperationResult<T>

但我认为泛型类型会按每个 T 生成类.

but I think generic type will generate class by every T.

推荐答案

You can do [DataContract(Name = "OperationResult")] 但实际上泛型在概念上不与想法混合RESTful 服务.

You can do [DataContract(Name = "OperationResult")] but really the generics conceptually don't mix will with the idea of RESTful services.

我建议创建一个新类,例如 class FacebookOperationResult : OperationResult{},然后将其用作您的返回类型.

I'd suggest creating a new class like class FacebookOperationResult : OperationResult<FacebookData> {} and then use that as your return type.

这篇关于当返回类型为 wcf 宁静服务中的泛型类型时,如何删除 xml 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆