1

我有一个使用外部 Web 服务的程序。我需要在请求中发送的 1 个字段是 DateTime 字段,但是即使我已经设置了它,它似乎永远不会出现,以及同一个对象中的许多其他字段,并且它们被很好地传递。

我放置了一个消息检查器并查看了它发送的内容,这是请求:

  <bettingRequest xmlns="">
    <accountPin>0</accountPin>
    <betDetailsRequestList>
      <acceptPartial>0</acceptPartial>
      <accumulatorBet>false</accumulatorBet>
      <accumulatorId>0</accumulatorId>
      <allUpFormula>0</allUpFormula>
      <betAmountList>
        <amountInvested>25</amountInvested>
        <returnsPerBet>0</returnsPerBet>
      </betAmountList>
      <betRefId>0</betRefId>
      <betType>Parimutuel</betType>
      <scheduledType>1</scheduledType>
      <fixedOddsProdCode>0</fixedOddsProdCode>
      <flexiBet>false</flexiBet>
      <legList>
        <prodCode>1</prodCode>
        <propositionNumber>0</propositionNumber>
        <raceNumber>2</raceNumber>
        <selectionList>
          <selectionName>TIM FIN</selectionName>
          <selectionNumber>6</selectionNumber>
          <selectionSeparator />
        </selectionList>
      </legList>
      <mystery>false</mystery>
      <notifyMethod>0</notifyMethod>
      <numMultiParlayBet>0</numMultiParlayBet>
      <ordinalNumber>1</ordinalNumber>
      <meetingCode>13</meetingCode>
    </betDetailsRequestList>
  </bettingRequest>

这是创建它的原因:

        bettingRequest betReq = new bettingRequest();
        betDetailsReq betDetReq = new betDetailsReq();

        List<legDetailsReq> leglist = new List<legDetailsReq>();
        List<betSelection> sellist = new List<betSelection>();
        List<betAmount> betamtlist = new List<betAmount>();
        List<betDetailsReq> betdetaillist = new List<betDetailsReq>();

        betSelection sel = new betSelection();
        sel.selectionNumber = selection.ToString();
        sel.selectionName = Runner;
        sel.selectionSeparator = "";
        sellist.Add(sel);

        legDetailsReq leg = new legDetailsReq();
        leg.prodCode = 1;
        leg.propositionNumber = 0;
        leg.raceNumber = racenum;
        leg.selectionList = sellist.ToArray();
        leglist.Add(leg);

        betAmount betAmt = new betAmount();
        betAmt.amountInvested = betamt;
        betAmt.returnsPerBet = "0";
        betamtlist.Add(betAmt);

        betDetReq.betType = "Parimutuel";
        betDetReq.betAmountList = betamtlist.ToArray();
        betDetReq.legList = leglist.ToArray();
        betDetReq.allUpFormula = "0";
        betDetReq.acceptPartial = 0;
        betDetReq.accumulatorBet = false;
        betDetReq.betRefId = 0;
        betDetReq.scheduledType = 1;
        betDetReq.fixedOddsProdCode = 0;
        betDetReq.flexiBet = false;
        betDetReq.mystery = false;
        betDetReq.notifyMethod = 0;
        betDetReq.ordinalNumber = 1;
        betDetReq.meetingCode = meetingcode;
        betDetReq.meetingDate = DateTime.Now;
        betdetaillist.Add(betDetReq);

        betReq.betDetailsRequestList = betdetaillist.ToArray();
        bettingResponse resp = bet.validateBet(meta, betReq);

这是序列化的代码:

    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=11)]
    public System.DateTime meetingDate {
        get {
            return this.meetingDateField;
        }
        set {
            this.meetingDateField = value;
            this.RaisePropertyChanged("meetingDate");
        }
    }

缺少的属性是 betDetReq.meetingDate,WSDL 可以在https://api.tab.com.au/tabapi/services/betting?wsdl查看

有人可以告诉我哪里出错了吗?我尝试了许多不同的 DataTime 变体,但都缺少相同的结果。

谢谢院长

4

1 回答 1

3

确保您已将“指定”属性设置为 true。

betDetReq.meetingDate = DateTime.Now;
betDetReq.meetingDateSpecified = true;

如果您有一个可选字段(即minOccurs属性为的字段0),则代理包含“指定”属性。除非您将此设置为 true,否则该字段不会添加到请求正文中。

于 2012-07-19T08:44:58.477 回答