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);
          }
      }

  • 相关阅读:
    swift 学习笔记
    collection view 开发笔记
    代码片段
    childViewController 小计
    iOS 二维码扫描
    statusbarhidden stuff 状态栏的各种特性
    AFNetworking 3.0 断点续传 使用记录
    scrollview 图片放大 捏合 瓦片地图 相关注意事项
    iOS 9 强制横屏
    简单的JS运动封装实例---侧栏分享到
  • 原文地址:https://www.cnblogs.com/fery/p/3490813.html
Copyright © 2011-2022 走看看