如何使用Web服务返回值创建一个空标记 [英] How Can I Create a Null Tag With Web Service Return Value

查看:79
本文介绍了如何使用Web服务返回值创建一个空标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的C#Web服务项目中有一个类和一个WebMethod,如下所示:

Hi,
I have a class and a WebMethod in my C# Web Service Project like this:

public class Results
{
    public int result1;
    public int result2;
    public string str1;
}

[WebMethod]
public Results getResults(int value1, int value2)
{
    Results results = new Results();
    results.result1 = value1 + value2;
    if (value1 > value2)
    {
        results.result2 = value1 - value2;
        results.str1 = "ok";
    }
    return results;
}



当我给出价值观时; value1:5 value2:3然后创建此XML:



When I give values; value1:5 value2:3 then this XML created:

<Results>
<result1>8</result1>
<result2>2</result2>
<str1>ok</str1>
</Results>



当我给出价值观时; value1:5 value2:8然后创建此XML:



And when I give values; value1:5 value2:8 then this XML created:

<Results>
<result1>13</result1>
<result2>0</result2>
</Results>



result2标签返回0值,并且str1标签不可见. C#自动为整数创建值为0的标记,而对于空字符串则不创建任何标记.
如何获得这样的答复???:



result2 tag returns 0 value and str1 tag is not visible. C# automaticly creates tag with value of 0 for integers, and no tags for null strings.
How can I get a response like this????:

<Results>
<result1>13</result1>
<result2></result2>
<str1></str1>
</Results>



我想创建所有带有值的标签.如果value为null,我可以创建null标签吗?
(< str1>/str1>或< str1/>)

谢谢.



I want to create all tags with values. If value is null, can i create null tag?
(<str1></str1> or <str1/>)

Thanks.

推荐答案

使用String.Empty代替null.


这篇关于如何使用Web服务返回值创建一个空标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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