WCF - xml 响应中的同名标签 [英] WCF - same name tags in xml response

查看:53
本文介绍了WCF - xml 响应中的同名标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手.请帮助我.在 WCF 休息应用程序中,我想要以下响应

I am a newbie. Plzz help me at this. In WCF rest application i want the following response

<parameterList>    
        <parameter>        
            <Question> Occupation </Question> 

            <Choice> Student/Others </Choice>      
            <Choice> Retired/housewife </Choice>       
            <Choice> Salaried/SelfEmployed </Choice>        
            <Choice> Doctor/CA/Socially Important Person </Choice> 

        </parameter>    
</parameterList>

我想要 4 个具有不同内容的相同选择"标签.我得到的只是最后一个选择"标签.

I want 4 same "choice" tags with different contents. What i am getting is only the last "choice" tag.

[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/getQuestion")]
[return: MessageParameter(Name = "parameterList")]
List<parameter> getQuestion();

Service.svc.cs

public List<parameter> getQuestion()
    {
        List<parameter> lstParameter = new List<parameter>();
        parameter param = new parameter();
        param.Question = " Occupation ";
        param.Choice = " Student/Others ";
        param.Choice = " Retired/housewife ";
        param.Choice = " Salaried/SelfEmployed ";
        param.Choice = " Doctor/CA/Socially Important Person ";
        lstParameter.Add(param);
        return lstParameter;
    }

parameter.cs

public class parameter
{
    public string Question
    {
        get{ } set{ }
    }

    public string Choice
    {
        get{ } set{ }
    }
}

推荐答案

已解决

        [XmlElement("Choice")]

        public List<string> Choice
        {
            get { return aChoice; }
            set { aChoice = value; }
        }

只需在属性上方添加 [XmlElement("")] 即可重命名 Xml 元素.

Just needed to add [XmlElement("")] above the property to rename the Xml Element.

谢谢詹姆斯.你很有帮助.

Thanx james. u were helpful.

这篇关于WCF - xml 响应中的同名标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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