WebService XML SoapFormatter

管理 NuGet 程序包
SoapFormatter

使用 FileStream 创建文件【SoapSerialize.xml】

[HttpGet()]
public IEnumerable Get()
{
  #region SoapFormatter Serialize
  Company companySerialize = new Company { name = "1234", code = 1 };
  SoapFormatter soapCreate = new SoapFormatter();
  using (FileStream streamCreate = new FileStream(@"D:\SoapSerialize.xml", FileMode.Create))
  {
    soapCreate.Serialize(streamCreate, companySerialize);
  }
  #endregion
}

使用 FileStream 读取文件【SoapSerialize.xml】

[HttpGet()]
public IEnumerable Get()
{
  #region SoapFormatter Deserialize
  Company companyDeserialize = null;
  SoapFormatter soapOpen = new SoapFormatter();
  using (FileStream streamOpen = new FileStream(@"D:\SoapSerialize.xml", FileMode.Open))
  {
    companyDeserialize = (Company)soapOpen.Deserialize(streamOpen);
  }
  var name = companyDeserialize.name;
  #endregion
}

Company

[Serializable]
public class Company
{
  public int code { get; set; }

  public string name { get; set; }
}

SoapSerialize.xml 文件


  
    
      <_x003C_code_x003E_k__BackingField>1
      <_x003C_name_x003E_k__BackingField id="ref-2">1234
    
  

*
*
*

你可能感兴趣的:(.Net技术,.NET,Core,XML)