Dean Harry
Dean Harry

Reputation: 267

DateTime missing from WCF request?

I have a program that is consuming an external web service. 1 of the fields I need to send in the request is a DateTime field however it seems to never be present even though I have set it, along with many others in the same object, and they are passed fine.

I put a message inspector and had a look at what it is sending, here is the request:

  <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>

and here is what creates it:

        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);

and here is the code for the serialization:

    [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");
        }
    }

The attribute that is missing is the betDetReq.meetingDate, the WSDL can be viewed at https://api.tab.com.au/tabapi/services/betting?wsdl

Can someone tell me where I am going wrong please? I have tried many different variations of DataTime all with the same missing result.

Thanks Dean

Upvotes: 1

Views: 640

Answers (1)

RB.
RB.

Reputation: 37172

Ensure you have set the "Specified" property to true.

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

If you have an optional field (i.e. one where the minOccurs attribute is 0), then the proxy includes a "Specified" property. Unless you set this to true, the field does not get added to the request body.

Upvotes: 3

Related Questions