TimeZoneInfo序列化问题c#

时间:2017-04-06 06:26:05

标签: c# wcf serialization timezone

我有一个序列化TimezoneInfo的问题,因为它没有无参数构造函数。我试图通过做这里建议的事情来解决它

https://social.msdn.microsoft.com/Forums/vstudio/en-US/a2bda890-41e9-47e8-b404-042d110e4f13/serializing-classes-containing-timezoneinfo?forum=netfxbcl

这是我的请求对象的样子

[MessageContract(WrapperNamespace = ServiceConstants.ContractNameSpaceMessageContract)]
public class GetTransactionsRequest
{
    [MessageHeader(Namespace = ServiceConstants.ContractNameSapceMessageHeader)]
    public DateTime EndDate { get; set; }

    [MessageHeader(Namespace = ServiceConstants.ContractNameSpaceMessageContract)]
    public DateTime StartDate { get; set; }

    [MessageHeader(Namespace = ServiceConstants.ContractNameSpaceMessageContract)]
    public string TimeZoneInfo
    {
        get { return tzInfo.ToSerializedString(); }
        set { tzInfo = System.TimeZoneInfo.FromSerializedString(value); }
    }

    private TimeZoneInfo tzInfo;
    public TimeZoneInfo TZInfo
    {
        get { return tzInfo; }
        internal set { tzInfo = value; }
    }

}

我有以下合约界面

[ServiceKnownType(typeof(System.TimeZoneInfo))]
[ServiceKnownType(typeof(System.TimeZoneInfo.AdjustmentRule))]
[ServiceKnownType(typeof(System.TimeZoneInfo.AdjustmentRule[]))]
[ServiceKnownType(typeof(System.TimeZoneInfo.TransitionTime))]
[ServiceKnownType(typeof(System.DayOfWeek))]

[ServiceContract(Name = "TransactionLobService", Namespace = ServiceConstants.ContractNameSpace)]
public interface ITransactionLobService
{

    [OperationContract]
    [WebGet(UriTemplate = "/GetTransactions")]
    [FaultContract(typeof(ExpenseAutomationFault))]
    GetTransactionsResponse GetTransactions(GetTransactionsRequest request);
}

我正在使用这样的服务

    Dim client As TransactionLobService = New TransactionLobServiceClient()

    Dim getTransactionsRequest As New TransactionsLOBService.GetTransactionsRequest() With {
        .TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time").ToSerializedString(),
        .StartDate = Convert.ToDateTime("2017-03-27 00:00:00"),
        .EndDate = DateTime.Now
    }

    Dim response = client.GetTransactions(getTransactionsRequest)

我仍然收到以下错误: -

System.InvalidOperationException:出现了反映类型' GetTransactionsRequest'的错误。 ---> System.InvalidOperationException:无法序列化成员' GetTransactionsRequest.TZInfo'类型' System.TimeZoneInfo',有关更多详细信息,请参阅内部异常。 ---> System.InvalidOperationException:System.TimeZoneInfo无法序列化,因为它没有无参数构造函数。

非常感谢任何帮助

0 个答案:

没有答案