WebService XML SoapFormatter Postman截图

76 篇文章 7 订阅
2 篇文章 1 订阅

XML 和 SOAP 序列化

管理 NuGet 程序包
SoapFormatter

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

[HttpGet()]
public IEnumerable<WeatherForecast> 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<WeatherForecast> 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 文件

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/clr/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <a1:Company id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/NewCapital.WebAPI.Controllers/NewCapital.WebAPI%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
      <_x003C_code_x003E_k__BackingField>1</_x003C_code_x003E_k__BackingField>
      <_x003C_name_x003E_k__BackingField id="ref-2">1234</_x003C_name_x003E_k__BackingField>
    </a1:Company>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Postman 调用 webservice
POST 请求
Headers参数:Content-Type:text/xml;charset=utf-8
Body row XML参数

*
*
*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值