Web服务中的对象不返回整数数据 [英] Web service not returning integer data in an object

查看:145
本文介绍了Web服务中的对象不返回整数数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/1184245/vs2003-web-reference-for-a-wcf-service-has-extra-idspecified-parameter\">VS2003 Web引用的WCF服务有多余的&QUOT; IdSpecified&QUOT;参数

谢谢大家。我完全错过了。是的,类名是可怕的。

Thanks everyone. I totally missed that. Yes, the class name is awful.

我有一个Web服务(ASMX),它返回包含数组的对象。

I have a web service (ASMX) that returns an object which contains an array.

我首先定义我的响应对象:

I first define my response object:

APIResponse response = new APIResponse();

填写一个DataTable:

Fill a datatable:

dtHolder = SqlHelper.ExecuteDatatable(connstring, CommandType.StoredProcedure, strSelect, aParams);

我查询的结果创建一个持有人:

Create a holder for the results of my query:

    API036RsBkgDetRec[] BkgDetRec_Array = new API036RsBkgDetRec[dtHolder.Rows.Count];
            int i = 0;

            foreach (DataRow row in dtHolder.Rows)
            {
                BkgDetRec_Array[i] = new API036RsBkgDetRec();

                BkgDetRec_Array[i].eqoEqszId = row[0].ToString();
                BkgDetRec_Array[i].eqoEqtpId = row[1].ToString();
                BkgDetRec_Array[i].eqoEqhtId = row[2].ToString();
                BkgDetRec_Array[i].qty = Convert.ToInt32(row[3]);
                BkgDetRec_Array[i].receiveQty = Convert.ToInt32(row[4]);
                BkgDetRec_Array[i].emptyTally = Convert.ToInt32(row[5]);
                BkgDetRec_Array[i].maxEmpty = Convert.ToInt32(row[6]);
                BkgDetRec_Array[i].chsQty = Convert.ToInt32(row[7]);
                BkgDetRec_Array[i].chsTally = Convert.ToInt32(row[8]);

                i++;
            }

和填充支架阵列我只是填充上面,我是返回数组(bkgDetTable):

and populate the array I am returning (bkgDetTable) with the holder array I just populated above:

response.bkgDetTable = BkgDetRec_Array;

当我捕获输出,我看到,即使当我经历了code步骤,他们正在与实数填充正在创建没有整型字段。对象API036RsBkgDetRec也有他们定义为整数值。只有定义为字符串的是未来的对面。

When I capture the output, I see that none of the integer fields are being created even though when I step through the code, they are being populated with real numbers. The object API036RsBkgDetRec also has them defined as integer values. Only the ones defined as string are coming across.

<bkgDetTable xmlns="http://sdfsd/xsd">
<eqoEqhtId>96</eqoEqhtId>
<eqoEqszId>40</eqoEqszId>
<eqoEqtpId>DR</eqoEqtpId>
</bkgDetTable>

下面是API036RsBkgDetRec的定义:

Here is the definition of API036RsBkgDetRec:

public partial class API036RsBkgDetRec
{    
private int chsQtyField;

private bool chsQtyFieldSpecified;

private int chsTallyField;

private bool chsTallyFieldSpecified;

private int emptyTallyField;

private bool emptyTallyFieldSpecified;

private string eqoEqhtIdField;

private string eqoEqszIdField;

private string eqoEqtpIdField;

private int maxEmptyField;

private bool maxEmptyFieldSpecified;

private int qtyField;

private bool qtyFieldSpecified;

private int receiveQtyField;

private bool receiveQtyFieldSpecified;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public int chsQty
{
    get
    {
        return this.chsQtyField;
    }
    set
    {
        this.chsQtyField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool chsQtySpecified
{
    get
    {
        return this.chsQtyFieldSpecified;
    }
    set
    {
        this.chsQtyFieldSpecified = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public int chsTally
{
    get
    {
        return this.chsTallyField;
    }
    set
    {
        this.chsTallyField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool chsTallySpecified
{
    get
    {
        return this.chsTallyFieldSpecified;
    }
    set
    {
        this.chsTallyFieldSpecified = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=2)]
public int emptyTally
{
    get
    {
        return this.emptyTallyField;
    }
    set
    {
        this.emptyTallyField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool emptyTallySpecified
{
    get
    {
        return this.emptyTallyFieldSpecified;
    }
    set
    {
        this.emptyTallyFieldSpecified = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=3)]
public string eqoEqhtId
{
    get
    {
        return this.eqoEqhtIdField;
    }
    set
    {
        this.eqoEqhtIdField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=4)]
public string eqoEqszId
{
    get
    {
        return this.eqoEqszIdField;
    }
    set
    {
        this.eqoEqszIdField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=5)]
public string eqoEqtpId
{
    get
    {
        return this.eqoEqtpIdField;
    }
    set
    {
        this.eqoEqtpIdField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=6)]
public int maxEmpty
{
    get
    {
        return this.maxEmptyField;
    }
    set
    {
        this.maxEmptyField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool maxEmptySpecified
{
    get
    {
        return this.maxEmptyFieldSpecified;
    }
    set
    {
        this.maxEmptyFieldSpecified = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=7)]
public int qty
{
    get
    {
        return this.qtyField;
    }
    set
    {
        this.qtyField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool qtySpecified
{
    get
    {
        return this.qtyFieldSpecified;
    }
    set
    {
        this.qtyFieldSpecified = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=8)]
public int receiveQty
{
    get
    {
        return this.receiveQtyField;
    }
    set
    {
        this.receiveQtyField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool receiveQtySpecified
{
    get
    {
        return this.receiveQtyFieldSpecified;
    }
    set
    {
        this.receiveQtyFieldSpecified = value;
    }
}
}

任何想法?

推荐答案

对于所有的 INT 字段,您有两个字段:

For all the INT fields, you have two fields:


  • 实际 INT 字段,我相信你已经设置为正确的值(私人诠释emptyTallyField;

  • the actual int field which I'm sure you're already setting to the proper value (private int emptyTallyField;)

但您有一个名为字段私人布尔emptyTallyFieldSpecified; 其中必须设置为真正 - 否则你设置int值的不会被序列化退出

but you also have a field called private bool emptyTallyFieldSpecified; which must be set to true - otherwise that int value you set will not be serialized out

这样做的原因是因为像字符串字段,你可以有一个引用类型字段 NULL 重新present的没有价值方面,你可以在那里有一个空字符串或任何其他字符串。

The reason for this is because for a reference-type field like a string field, you can have NULL to represent the "there is no value" aspect, and you can have an empty string or any other string in there.

有关价值类型,如 INT - 要不然怎么会重新present了有没有值指定的情况?如果您设置的int字段为0 - 是0,因为你想要的零作为值,或者是0,因为你真正想说没有价值。出于这个原因,所有值类型都有这种额外的(字段名)指定的指示的实际值是否为present 属性。如果没有设置指定的标志(和它的不是默认设置),那么你有没有价值 - 因此没有被序列化了。

For value types, like int - how else would you represent the "there is no value specified" case? If you set the int field to 0 - is that 0 because you want that "zero" as the value, or is that "0" because you really want to say "there is no value". For this reason, all value types have this additional (fieldname)specified property which indicates whether or not an actual value is present. If that specified-flag is not set (and it's not set by default), then you have no value - thus nothing gets serialized out.

这篇关于Web服务中的对象不返回整数数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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