zoukankan      html  css  js  c++  java
  • Deserializing/Serializing SOAP Messages in C#

       /// <summary>
       /// Converts a SOAP string to an object
       /// </summary>
       /// <typeparam name="T">Object type</typeparam>
       /// <param name="SOAP">SOAP string</param>
       /// <returns>The object of the specified type</returns>
       public static T SOAPToObject<T>(string SOAP)
       {
           if (string.IsNullOrEmpty(SOAP))
          {
              throw new ArgumentException("SOAP can not be null/empty");
          }

          using (MemoryStream Stream = new MemoryStream(UTF8Encoding.UTF8.GetBytes(SOAP)))
          {
              SoapFormatter Formatter = new SoapFormatter();

              return (T)Formatter.Deserialize(Stream);
          }
      }
      

      /// <summary>
      /// Converts an object to a SOAP string
      /// </summary>
      /// <param name="Object">Object to serialize</param>
      /// <returns>The serialized string</returns>
      public static string ObjectToSOAP(object Object)
      {
          if (Object == null)
          {
              throw new ArgumentException("Object can not be null");
          }

          using (MemoryStream Stream = new MemoryStream())
          {
              SoapFormatter Serializer = new SoapFormatter();
              Serializer.Serialize(Stream, Object);
              Stream.Flush();

              return UTF8Encoding.UTF8.GetString(Stream.GetBuffer(), 0, (int)Stream.Position);
          }
      }

  • 相关阅读:
    element-ui 后台问题
    element-ui 使用:rules对表单字段进行验证
    扫码枪 移动端监听
    前端好用工具介绍——wulihub
    移动端 扫描枪输入不弹出键盘
    移动端 input输入实时监听查询数据渲染
    新老系统统一认证解决方案
    转 高性能IO模型浅析
    数据库备份方案
    软件开发阶段数据库升级维护策略
  • 原文地址:https://www.cnblogs.com/fery/p/3490813.html
Copyright © 2011-2022 走看看