Guest User

Untitled

a guest
Jan 17th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. [XmlRpcMethod("ticket.get")] //
  2. object[] get(int id);
  3.  
  4.  
  5. [XmlRpcMethod("ticket.getActions")] //
  6. object[] getActions(int id);
  7.  
  8.  
  9. }
  10.  
  11. public DHL()
  12. {
  13. InitializeComponent();
  14.  
  15. }
  16.  
  17. private void DHL_Load(object sender, EventArgs e)
  18. {
  19.  
  20. }
  21.  
  22. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  23. {
  24.  
  25. }
  26.  
  27. private void button1_Click(object sender, EventArgs e)
  28. {
  29.  
  30.  
  31.  
  32. int id = 6;
  33. get(id);
  34. }
  35. private void get(int id)
  36.  
  37. {
  38.  
  39.  
  40. Trac proxy;
  41. string user = "uzer";
  42. string password = "parol";
  43. proxy = XmlRpcProxyGen.Create<Trac>();
  44. proxy.Credentials = new System.Net.NetworkCredential(user, password);
  45. object[] arr = proxy.get(id);
  46. BinaryFormatter formatter = new BinaryFormatter();
  47. using (FileStream fs = new FileStream("arr.dat", FileMode.OpenOrCreate))
  48. {
  49. formatter.Serialize(fs, arr);// тут и ошибка, что Тип CookComputing.XmlRpc.XmlRpcStruct в сборке CookComputing.XmlRpcV2, Version=3.0.0.0, Culture=neutral, PublicKeyToken=a7d6e17aa302004d не отмечен как сериализуемый.
  50. }
  51.  
  52.  
  53. }
  54.  
  55. private void button4_Click(object sender, EventArgs e)
  56. {
  57. int id = 6;
  58.  
  59. getActions( id);
  60. }
  61. private void getActions(int id)
  62. {
  63. Trac proxy;
  64. string user = "uzer";
  65. string password = "parol";
  66. proxy = XmlRpcProxyGen.Create<Trac>();
  67. proxy.Credentials = new System.Net.NetworkCredential(user, password);
  68. object[] arr = proxy.getActions(id);
  69. BinaryFormatter formatter = new BinaryFormatter();
  70. using (FileStream fs = new FileStream("arr.dat", FileMode.OpenOrCreate))
  71. {
  72. formatter.Serialize(fs, arr);//а тут нет такой ошибки
  73. }
  74.  
  75.  
  76. }
  77.  
  78.  
  79. }
  80.  
  81. public class Person
  82. {
  83. public string Name { get; set; }
  84. public int Age { get; set; }
  85. public DriversLicense License;
  86. }
  87.  
  88.  
  89. // An instance of this type will be part of the object graph and will need to be
  90. // serialized also.
  91. public class DriversLicense
  92. {
  93. public string Number { get; set; }
  94. }
  95.  
  96. public class PersonSurrogate : ISerializationSurrogate
  97. {
  98. /// <summary>
  99. /// Manually add objects to the <see cref="SerializationInfo"/> store.
  100. /// </summary>
  101. public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
  102. {
  103. Person person = (Person) obj;
  104. info.AddValue("Name", person.Name);
  105. info.AddValue("Age", person.Age);
  106. info.AddValue("License", person.License);
  107. }
  108.  
  109. /// <summary>
  110. /// Retrieves objects from the <see cref="SerializationInfo"/> store.
  111. /// </summary>
  112. /// <returns></returns>
  113. public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
  114. {
  115. Person person = (Person)obj;
  116. person.Name = info.GetString("Name");
  117. person.Age = info.GetInt32("Age");
  118. person.License = (DriversLicense) info.GetValue("License", typeof(DriversLicense));
  119. return person;
  120. }
  121. }
  122.  
  123. public class DriversLicenseSurrogate : ISerializationSurrogate
  124. {
  125. /// <summary>
  126. /// Manually add objects to the <see cref="SerializationInfo"/> store.
  127. /// </summary>
  128. public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
  129. {
  130. DriversLicense license = (DriversLicense)obj;
  131. info.AddValue("Number", license.Number);
  132. }
  133.  
  134. /// <summary>
  135. /// Retrieves objects from the <see cref="SerializationInfo"/> store.
  136. /// </summary>
  137. /// <returns></returns>
  138. public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
  139. {
  140. DriversLicense license = (DriversLicense)obj;
  141. license.Number = info.GetString("Number");
  142. return license;
  143. }
  144. }
  145.  
  146. private static void SerializePerson(Person person)
  147. {
  148. if (person == null)
  149. throw new ArgumentNullException("person");
  150.  
  151. using (var memoryStream = new MemoryStream())
  152. {
  153. //Configure our surrogate selectors.
  154. var surrogateSelector = new SurrogateSelector();
  155. surrogateSelector.AddSurrogate(typeof (Person), new StreamingContext(StreamingContextStates.All),
  156. new PersonSurrogate());
  157. surrogateSelector.AddSurrogate(typeof (DriversLicense), new StreamingContext(StreamingContextStates.All),
  158. new DriversLicenseSurrogate());
  159.  
  160. //Serialize the object
  161. IFormatter formatter = new BinaryFormatter();
  162. formatter.SurrogateSelector = surrogateSelector;
  163. formatter.Serialize(memoryStream, person);
  164.  
  165. //Return to the beginning of the stream
  166. memoryStream.Seek(0, SeekOrigin.Begin);
  167.  
  168. //Deserialize the object
  169. Person deserializedPerson = (Person) formatter.Deserialize(memoryStream);
  170. }
  171. }
Add Comment
Please, Sign In to add comment