HttpWebRequest Won't Serialize

后端 未结 2 865
别跟我提以往
别跟我提以往 2021-01-21 11:22

I\'m getting the following error when I try to Serialize an HttpWebRequest

Type \'System.Net.KnownHttpVerb\' in Assembly \'System, Version=2.0.0.0, Cu

相关标签:
2条回答
  • 2021-01-21 11:28

    Well, if one of the contained objects is marked as non-serializable, I believe you're "out of luck" using the default serializer.

    If possible, I would recommend instead taking the parameters used to instantiate your web request and serializing those instead. Write a custom serializer/deserializer to reconstitute the uncooperative object.

    EDIT: There's a fairly good article on it here.

    EDIT2: In fact, after a little googling, it appears that this is your only option, as the Serializable attribute on HttpWebRequest has been marked obsolete as of .net 2.0. See here for details (search for HttpWebRequest).

    0 讨论(0)
  • 2021-01-21 11:36

    System.Net.HttpWebRequest serialization was marked as obselete in .NET 2.0.

    Official documents here:

    http://msdn.microsoft.com/en-us/library/aa497288.aspx

    From an app perspective this is the best outcome. The predominant bulk of an HttpWebRequest instance is IO state that is typically not directly rehydratable.

    As @Andrew-Rollings suggests instead implement a custom serialize to store/restore your request parameters, then recreate the HttpWebRequest instance from scratch.

    0 讨论(0)
提交回复
热议问题