将DateTime发送到默认序列化的WCF服务

时间:2015-06-11 18:02:00

标签: c# wcf datetime serialization

所以我有以下课程:

// the element you're showing has an id, so there is only ever one
$cn = $html->find('#coursename');
$h1 = $cn->find('h1');

// get both the "full" text, and the "text we don't want":
$a = $h1.innertext;
$b = $h1->find('span').innertext;

// now we just remove $b from $a.
// We don't need to edit the HTML to achieve that:
$actual_text = str_replace($b, '', $a);

我在我的WCF上使用它,如下所示: (接口)

[DataContract]
public class Client
{
    [DataMember]
    public int ClientID { get; set; }
    [DataMember]
    public int MerchantID { get; set; }
    [DataMember]
    public string ClientName { get; set; }
    [DataMember]
    public Nullable<System.DateTime> LastPing { get; set; }
    [DataMember]
    public Nullable<System.Guid> SessionToken { get; set; }
    [DataMember]
    public System.Guid GUID { get; set; }
    [DataMember]
    public string Password { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string Email { get; set; }
    [DataMember]
    public string Address { get; set; }
    [DataMember]
    public DateTime cDate { get; set; }
    [DataMember]
    public string AdditionalInfo { get; set; }

}

和WCF实施:

    [OperationContract]
    [ServiceKnownType(typeof(Client))]
    void CreateClient(Client inClient);

我有另一个项目(网站类型),我正在调用该服务:

    public void CreateClient(Client inClient)
    {
        try
        {
            CMSUsersManager manager = new CMSUsersManager();
            manager.CreateClient(inClient);
        }
        catch (Exception ex)
        {

        }
    }

现在我的问题: 网站上的“inClient”包含 CPanelService.CPanelService service; service = new CPanelService.CPanelService(); service.CreateClient(inClient); 。 当请求发送到WCF时,服务会收到inClient.cDate = DateTime.Now

我试图弄清楚,没有运气。

有人可以赐教吗? 感谢。

1 个答案:

答案 0 :(得分:0)

要通过网络发送属性,您必须在其标题上方明确输入数据注释[DataMember]

[DataMember]
public string Email { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public System.DateTime cDate { get; set; }

为您的所有财产执行此操作。

在课程标题上你还放了[DataContract]

[DataContract]
public class Client

我不确定这会解决您的问题,但如果您不添加这些注释,我可以保证您最终会遇到序列化(这似乎是您当前的问题)。