有一项服务已迁移到WCF。大多数方法都有int,string,DateTime参数,一切正常,但是一个方法接收一组自定义类对象。
[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
}
我在界面中添加了所有ServiceContract
,OperationContract
属性。
为什么Dates 01.01.0001和Amounts 0.00,就像阵列成员再次构建一样?
其他服务工作正常,没有任何具体的......
简化的客户端代码:
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;
}
答案 0 :(得分:1)
我们遇到了类似的问题。尝试更新*** Specified属性,看看是否有效。它为我们做了:
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;
}