我正在尝试使用 c# 在 2 个 .Net 应用程序之间交换数据。
为了交换通信,我按照本教程介绍了基本的 HTTP 服务,它与字符串交换完美配合。
现在,我想发送我的自定义对象,但是当我重新生成服务时,新方法也Message chat(Message msg)
没有映射。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace StairWays.Messaging
{
/// <summary>
/// Classe permettant d'échanger des messages unifiés entre les différentes couches/fonctions
/// </summary>
[Serializable()]
public class Message : ISerializable
{
/// <summary>
/// Identification de l'emetteur
/// </summary>
public string sender { get; private set; }
/// <summary>
/// Service demandé
/// </summary>
public string invoke { get; private set; }
/// <summary>
/// Statut de l'opération demandée
/// </summary>
public bool status { get; private set; }
/// <summary>
/// Informations complémentaires
/// </summary>
public string info { get; private set; }
/// <summary>
/// Données à transférer
/// </summary>
public object[] data { get; private set; }
/// <summary>
/// Jeton de sécurité de l'application
/// </summary>
public string token { get; private set; }
/// <summary>
/// Constructeur permettant de construire le message permettant l'échange uniformisé
/// </summary>
/// <param name="sender">Identification de l'emetteur du message</param>
/// <param name="Invoke">Nommage du service demandé</param>
/// <param name="status">Permet au récepteur d'indiquer au destinataire si le traitement de l'opération demandé est un succès ou un échec</param>
/// <param name="info">Informations complémentaires</param>
/// <param name="data">Données à transférer</param>
/// <param name="token">Jeton de sécurité de l'application</param>
public Message(string sender, string invoke, bool status, string info, object[] data, string token)
{
this.sender = sender;
this.invoke = invoke;
this.status = status;
this.info = info;
this.data = data;
this.token = token;
}
/// <summary>
/// Deserialization constructor.
/// </summary>
/// <param name="info"></param>
/// <param name="ctxt"></param>
public Message(SerializationInfo info, StreamingContext ctxt)
{
this.sender = (String)info.GetValue("sender", typeof(string));
this.invoke = (String)info.GetValue("invoke", typeof(string));
this.status = (bool)info.GetValue("status", typeof(bool));
this.info = (String)info.GetValue("info", typeof(string));
this.data = (Object[])info.GetValue("data",typeof(Object[]));
this.token = (String)info.GetValue("token", typeof(string)); ;
}
/// <summary>
/// Serialization function.
/// </summary>
/// <param name="info"></param>
/// <param name="ctxt"></param>
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
//You can use any custom name for your name-value pair. But make sure you
// read the values with the same name. For ex:- If you write EmpId as "EmployeeId"
// then you should read the same with "EmployeeId"
info.AddValue("sender", sender);
info.AddValue("invoke", invoke);
info.AddValue("status", status);
info.AddValue("info", info);
info.AddValue("data", data);
info.AddValue("token", token);
}
}
}