Serialize Class to Soap message : Serialization SOAP « File Stream « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » File Stream » Serialization SOAPScreenshots 
Serialize Class to Soap message

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;

public class Serializer {

  public static void Main(string [] args) {
    StudentList personnel = CreateStudentList();
    IFormatter soapFormatter = new SoapFormatter();
    using (FileStream stream = File.OpenWrite("StudentListSoap.xml")) {
      soapFormatter.Serialize(stream,personnel);
    }
  }
  
  private static StudentList CreateStudentList() {
    StudentList personnel = new StudentList();
    personnel.Students = new Employee [] {new Employee()};
    personnel.Students[0].FirstName = "Apple";
    personnel.Students[0].MiddleInitial = "M";
    personnel.Students[0].LastName = "Bear";
    
    personnel.Students[0].Addresses = new Address [] {new Address()};
    personnel.Students[0].Addresses[0].AddressType = AddressType.Home;
    personnel.Students[0].Addresses[0].Street = new string [] {"Culloden"};
    personnel.Students[0].Addresses[0].City = "Vancouver";
    personnel.Students[0].Addresses[0].State = State.BC;
    personnel.Students[0].Addresses[0].Zip = "V5V 4X7";
    
    personnel.Students[0].StartDate = new DateTime(2006,10,12);
    
    return personnel;
  }
}

[Serializable]
public enum AddressType {
  Home,
  Office
}

[Serializable]
public enum State {
  BC, ON
}

[Serializable]
public class Address {
  public AddressType AddressType;
  public string[] Street;
  public string City;
  public State State;
  public string Zip;
}

[Serializable]
public class TelephoneNumber {
  public string AreaCode;
  public string Exchange;
  public string Number;
}

[Serializable]
public class Employee {
  public string FirstName;
  public string MiddleInitial;
  public string LastName;
  public Address [] Addresses;
  public TelephoneNumber [] TelephoneNumbers;
  public DateTime StartDate;
}

[Serializable]
public class StudentList {
  public Employee [] Students;
}

           
       
Related examples in the same category
1.Serialize to SOAP based XML fileSerialize to SOAP based XML file
2.Use SoapFormatter
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.