1

There is a service which is migrated to WCF. The most methods have int, string, DateTime parameters and everything is working fine, but one method receives an array of custom class objects.

[DataContract]
public class Term
{
    [DataMember]
    public DateTime Date;
    [DataMember]
    public decimal Amount;
}

//

public int UpdateTerm(int id, int documentId, Term[] terms)
{
  // it receives the passed Term array with all objects 
  // but here all the Dates are 01.01.0001 and all Amounts are 0.00
}

I have added all the ServiceContract, OperationContract attributes in the Interface. Why are Dates 01.01.0001 and Amounts 0.00, like the array members were constructed again? Other services are working OK, there isn't anything specific..

Simplified client code:

Term[] terms = new Term[3];
for (int i = 0; i < rows.Length; ++i)
{
  terms[i] = new Term();
  terms[i].Amount = 10;
  terms[i].Date = DateTime.Now;
}

MyService service = new MyService();
try
{
  id = service.UpdateTerm(1, 2, terms);
  service.Close();
}
catch
{
  service.Abort();
  throw;
}
va.
  • 848
  • 3
  • 17
  • 39
  • is terms marked as a [DataContract], the properties of that class need to be marked as [DataMember] – T McKeown Dec 26 '13 at 16:05
  • @TMcKeown yes they are marked as You can see :) – va. Dec 26 '13 at 16:07
  • did you possibly add these attributes after the client originally got the stub classes? Have you updated the service reference from the client to ensure you have a current version of this datacontract class? – T McKeown Dec 26 '13 at 16:10
  • I guess you would had in order to set them on client... hmm.. – T McKeown Dec 26 '13 at 16:13
  • The service and that class with attributes were created before few months. By this time service has been published un service references updated about 50 times.. Sorry, I didn't understand Your last comment. For example I create an array of 3 elements and dates are 03.04.2013. I can see that in debug before calling service.UpdateTerm(...). And in service debug I see those 3 elements with dates 01.01.0001. – va. Dec 26 '13 at 16:20
  • can you share your client code? – T McKeown Dec 26 '13 at 16:22
  • @TMcKeown just added simplified client code – va. Dec 26 '13 at 16:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/43935/discussion-between-t-mckeown-and-user646263) – T McKeown Dec 26 '13 at 16:36
  • Why your loop is limited by some `rows.Length`? Here: `for (int i = 0; i < rows.Length; ++i)` what is rows.Length? – Tony Dec 26 '13 at 16:39
  • @Tony actually my array should be populated from `DataRow[] rows` which is the same length. I think it is not important, so I simplified the code. – va. Dec 26 '13 at 16:43

1 Answers1

1

We just ran across a similar issue. Try updating the ***Specified property and see if that works. It did for us:

Term[] terms = new Term[3];
for (int i = 0; i < rows.Length; ++i)
{
  terms[i] = new Term();
  terms[i].Amount = 10;
  terms[i].Date = DateTime.Now;
  terms[i].AmountSpecified = true;
  terms[i].DateSpecified = true;
}
mattkab
  • 728
  • 5
  • 8
  • Thanks @mattkab, I will try this later. As these `Term`s were formatted to CSV string in the service, I have found a workaround by passing a string already from the application. – va. Feb 15 '14 at 19:47