当前位置: 首页>>代码示例>>C#>>正文


C# SoapAttributeAttribute构造函数代码示例

本文整理汇总了C#中System.Xml.Serialization.SoapAttributeAttribute.SoapAttributeAttribute构造函数的典型用法代码示例。如果您正苦于以下问题:C# SoapAttributeAttribute构造函数的具体用法?C# SoapAttributeAttribute怎么用?C# SoapAttributeAttribute使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。您也可以进一步了解该构造函数所在System.Xml.Serialization.SoapAttributeAttribute的用法示例。


在下文中一共展示了SoapAttributeAttribute构造函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

public class Group
{
   // This attribute will be overridden.
   [SoapAttribute (Namespace = "http://www.cpandl.com")]
   public string GroupName;
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeOverride("SoapOveride.xml");
   }

   public void SerializeOverride(string filename)
   {
      // Create an instance of the XmlSerializer class
      // that overrides the serialization.
      XmlSerializer overRideSerializer = CreateOverrideSerializer();

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      myGroup.GroupName = ".NET";

      // Serialize the class, and close the TextWriter.
      overRideSerializer.Serialize(writer, myGroup);
       writer.Close();
   }

   private XmlSerializer CreateOverrideSerializer(){
    
      SoapAttributeOverrides mySoapAttributeOverrides = 
        new SoapAttributeOverrides();
      SoapAttributes mySoapAttributes = new SoapAttributes();
      // Create a new SoapAttributeAttribute to override the 
      // one applied to the Group class. The resulting XML 
      // stream will use the new namespace and attribute name.
      SoapAttributeAttribute mySoapAttribute = 
      new SoapAttributeAttribute();
      mySoapAttribute.AttributeName = "TeamName";
      // Change the Namespace.
      mySoapAttribute.Namespace = "http://www.cohowinery.com";

      mySoapAttributes.SoapAttribute = mySoapAttribute;
      mySoapAttributeOverrides.
      Add(typeof(Group), "GroupName" ,mySoapAttributes);
    
      XmlTypeMapping myMapping = (new SoapReflectionImporter
        (mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));
    
      XmlSerializer ser = new XmlSerializer(myMapping);
      return ser;
   }
}
//<?xml version="1.0" encoding="utf-8" ?> 
// <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
//xmlns:xsd="http://www.w3.org/2001/XMLSchema" n1:TeamName=".NET" 
//xmlns:n1="http://www.cohowinery" />
开发者ID:.NET开发者,项目名称:System.Xml.Serialization,代码行数:70,代码来源:SoapAttributeAttribute

示例2: Main

//引入命名空间
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

[SoapInclude(typeof(Vehicle))]
public class Group
{
   [SoapAttribute (Namespace = "http://www.cpandl.com")]
   public string GroupName;
   
   [SoapAttribute(DataType = "base64Binary")]
   public Byte [] GroupNumber;

   [SoapAttribute(DataType = "date", AttributeName = "CreationDate")]
   public DateTime Today;
   [SoapElement(DataType = "nonNegativeInteger", ElementName = "PosInt")]
   public string PostitiveInt;

   public Vehicle GroupVehicle;
}
  
public class Vehicle
{
   public string licenseNumber;
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("SoapAtts.xml");
      test.DeserializeObject("SoapAtts.xml");
   }
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class that
      // can generate encoded SOAP messages.
      XmlSerializer mySerializer =  ReturnSOAPSerializer();

      Group myGroup=MakeGroup();
      // Writing the file requires a TextWriter.
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
      writer.WriteEndElement();
      writer.Close();
   }

   private Group MakeGroup(){
      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      myGroup.GroupName = ".NET";

      Byte [] hexByte = new Byte[2]{Convert.ToByte(100),
      Convert.ToByte(50)};
      myGroup.GroupNumber = hexByte;

      DateTime myDate = new DateTime(2002,5,2);
      myGroup.Today = myDate;
      myGroup.PostitiveInt= "10000";
      myGroup.GroupVehicle = new Vehicle();
      myGroup.GroupVehicle.licenseNumber="1234";
      return myGroup;
   }   	

   public void DeserializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class that
      // can generate encoded SOAP messages.
      XmlSerializer mySerializer =  ReturnSOAPSerializer();

      // Reading the file requires an  XmlTextReader.
      XmlTextReader reader= 
      new XmlTextReader(filename);
      reader.ReadStartElement("wrapper");

      // Deserialize and cast the object.
      Group myGroup; 
      myGroup = (Group) mySerializer.Deserialize(reader);
      reader.ReadEndElement();
      reader.Close();
   }
   
   private XmlSerializer ReturnSOAPSerializer(){
      // Create an instance of the XmlSerializer class.
      XmlTypeMapping myMapping = 
      (new SoapReflectionImporter().ImportTypeMapping
      (typeof(Group)));
       return new XmlSerializer(myMapping);
   }
}
开发者ID:.NET开发者,项目名称:System.Xml.Serialization,代码行数:101,代码来源:SoapAttributeAttribute


注:本文中的System.Xml.Serialization.SoapAttributeAttribute.SoapAttributeAttribute构造函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。