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

  • 相关阅读:
    xml根据属性去重。如csprj去重
    table中td的内容换行。
    基于jq的表单填充
    c#包含类文件到csprj中
    t4 根据表名数组生成实体
    js中找string中重复项最多的字符个数
    一步步配置cordova android开发环境
    .net framework卸载工具
    Sql Server查询视图和表
    DbHelper.ttinclude 更新,查询视图和表
  • 原文地址:https://www.cnblogs.com/fery/p/3490813.html
Copyright © 2011-2022 走看看