[英]Datetime value getting reset in wcf service on using as a web reference and not with using as a service reference
I have a WCF Service with operation as follow: 我有一个WCF服务,操作如下:
public void setNotifications(List<AnnouncementDataContract> announcements)
{
foreach(AnnouncementDataContract item in announcements)
{
ent.InsertAnnouncements(item.Anc_Text, item.Anc_Date);
}
}
When I add this WCF service as a webreference in my MVC application and calls the method as follow: 当我在MVC应用程序中将此WCF服务添加为Webreference并按如下方式调用方法时:
MyService.Service1 proxy = new MyService.Service1();
Collection<MyService.AnnouncementDataContract> dc = new
Collection<MyService.AnnouncementDataContract>();
MyService.AnnouncementDataContract dc1 = new
MyService.AnnouncementDataContract();
dc1.anc_Date = System.DateTime.Now;
dc1.anc_Text = "Announcement1";
dc.Add(dc1);
proxy.setNotifications(dc.ToArray());
The value in each item for "announcements" at the service operation is reset and i get it as min datetime value not the one i have sent from my MVC application on calling the operation. 服务操作中“公告”的每个项目中的值都将重置,我将其作为最小日期时间值获得,而不是我从MVC应用程序在调用操作时发送的值。
But when I add this WCF service as a service reference in my MVC application and calls the operation, it works fine and the correct value of datetime is obtained at service. 但是,当我将此WCF服务添加为我的MVC应用程序中的服务引用并调用该操作时,它可以正常工作,并且在服务中获得了正确的datetime值。
I just had the same problem. 我只是有同样的问题。 It is because the generated proxy code for your AnnouncementDataContract class also creates a property called Anc_DateSpecified, which has to be set to true. 这是因为为您的AnnouncementDataContract类生成的代理代码还会创建一个称为Anc_DateSpecified的属性,该属性必须设置为true。 This is the case for all value types. 所有值类型都是这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.