Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [XmlRpcUrl("https://blabala.com/rpc")] // описание методов
- public interface Trac : IXmlRpcProxy
- {
- [XmlRpcMethod("ticket.get")] //
- object[] get(int id);
- [XmlRpcMethod("ticket.getActions")] //
- object[] getActions(int id);
- }
- public partial class DHL : Form
- {
- public DHL()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- int id = 6;
- get(id);
- }
- private void get(int id)
- {
- Trac proxy;
- string user = "uzer";
- string password = "parol";
- proxy = XmlRpcProxyGen.Create<Trac>();
- proxy.Credentials = new System.Net.NetworkCredential(user, password);
- object[] arr = proxy.get(id);
- BinaryFormatter formatter = new BinaryFormatter();
- using (FileStream fs = new FileStream("arr.dat", FileMode.OpenOrCreate))
- {
- formatter.Serialize(fs, arr);// тут и ошибка, что Тип CookComputing.XmlRpc.XmlRpcStruct в сборке CookComputing.XmlRpcV2, Version=3.0.0.0, Culture=neutral, PublicKeyToken=a7d6e17aa302004d не отмечен как сериализуемый.
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- int id = 6;
- getActions( id);
- }
- private void getActions(int id)
- {
- Trac proxy;
- string user = "uzer";
- string password = "parol";
- proxy = XmlRpcProxyGen.Create<Trac>();
- proxy.Credentials = new System.Net.NetworkCredential(user, password);
- object[] arr = proxy.getActions(id);
- BinaryFormatter formatter = new BinaryFormatter();
- using (FileStream fs = new FileStream("arr.dat", FileMode.OpenOrCreate))
- {
- formatter.Serialize(fs, arr);//а тут нет такой ошибки
- }
- }
- }
- public class Person
- {
- public string Name { get; set; }
- public int Age { get; set; }
- public DriversLicense License;
- }
- // An instance of this type will be part of the object graph and will need to be
- // serialized also.
- public class DriversLicense
- {
- public string Number { get; set; }
- }
- public class PersonSurrogate : ISerializationSurrogate
- {
- /// <summary>
- /// Manually add objects to the <see cref="SerializationInfo"/> store.
- /// </summary>
- public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
- {
- Person person = (Person) obj;
- info.AddValue("Name", person.Name);
- info.AddValue("Age", person.Age);
- info.AddValue("License", person.License);
- }
- /// <summary>
- /// Retrieves objects from the <see cref="SerializationInfo"/> store.
- /// </summary>
- /// <returns></returns>
- public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
- {
- Person person = (Person)obj;
- person.Name = info.GetString("Name");
- person.Age = info.GetInt32("Age");
- person.License = (DriversLicense) info.GetValue("License", typeof(DriversLicense));
- return person;
- }
- }
- public class DriversLicenseSurrogate : ISerializationSurrogate
- {
- /// <summary>
- /// Manually add objects to the <see cref="SerializationInfo"/> store.
- /// </summary>
- public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
- {
- DriversLicense license = (DriversLicense)obj;
- info.AddValue("Number", license.Number);
- }
- /// <summary>
- /// Retrieves objects from the <see cref="SerializationInfo"/> store.
- /// </summary>
- /// <returns></returns>
- public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
- {
- DriversLicense license = (DriversLicense)obj;
- license.Number = info.GetString("Number");
- return license;
- }
- }
- private static void SerializePerson(Person person)
- {
- if (person == null)
- throw new ArgumentNullException("person");
- using (var memoryStream = new MemoryStream())
- {
- //Configure our surrogate selectors.
- var surrogateSelector = new SurrogateSelector();
- surrogateSelector.AddSurrogate(typeof (Person), new StreamingContext(StreamingContextStates.All),
- new PersonSurrogate());
- surrogateSelector.AddSurrogate(typeof (DriversLicense), new StreamingContext(StreamingContextStates.All),
- new DriversLicenseSurrogate());
- //Serialize the object
- IFormatter formatter = new BinaryFormatter();
- formatter.SurrogateSelector = surrogateSelector;
- formatter.Serialize(memoryStream, person);
- //Return to the beginning of the stream
- memoryStream.Seek(0, SeekOrigin.Begin);
- //Deserialize the object
- Person deserializedPerson = (Person) formatter.Deserialize(memoryStream);
- }
- }
Add Comment
Please, Sign In to add comment