Click here to Skip to main content
15,887,936 members
Home / Discussions / C#
   

C#

 
AnswerRe: help Pin
CPallini22-Apr-09 4:41
mveCPallini22-Apr-09 4:41 
AnswerRe: help Pin
Thomas ST22-Apr-09 4:45
Thomas ST22-Apr-09 4:45 
QuestionObject "type not expected" when using serialization in web services Pin
BASONJS22-Apr-09 4:03
BASONJS22-Apr-09 4:03 
AnswerRe: Object "type not expected" when using serialization in web services Pin
Thomas ST22-Apr-09 4:59
Thomas ST22-Apr-09 4:59 
GeneralRe: Object "type not expected" when using serialization in web services Pin
BASONJS22-Apr-09 5:14
BASONJS22-Apr-09 5:14 
GeneralRe: Object "type not expected" when using serialization in web services Pin
Thomas ST22-Apr-09 20:57
Thomas ST22-Apr-09 20:57 
GeneralRe: Object "type not expected" when using serialization in web services Pin
BASONJS22-Apr-09 23:04
BASONJS22-Apr-09 23:04 
GeneralRe: Object "type not expected" when using serialization in web services Pin
BASONJS23-Apr-09 5:29
BASONJS23-Apr-09 5:29 
I have got to this point.

The classes are all now in this format:

using System;
using System.Collections;
using System.Xml.Serialization;
using System.Xml;

namespace Data.Package
{
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "Data.Package", TypeName = "Changes")]
    public class Changes
    {
        private Boolean blnIsDirty;
        private Boolean blnIsNew;
  
        public Changes() 
        {
            this.blnIsDirty = false;
            this.blnIsNew = true;
        }

        [System.Xml.Serialization.XmlElementAttribute(ElementName = "IsDirty")]
        public Boolean IsDirty
        {
            get { return blnIsDirty; }

            set { blnIsDirty = value; }
        }

        [System.Xml.Serialization.XmlElementAttribute(ElementName = "IsNew")]
        public Boolean IsNew
        {
            get { return blnIsNew; }

            set { blnIsNew = value; }
        }
    }
}


My serialization class is as follows:

using System;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;

namespace Helper
{
    public class Serializer
    {
        public Serializer() 
        { 
        
        }

        /// <summary>
        /// Method to convert a custom Object to XML string
        /// </summary>
        /// <param name="pObject">Object that is to be serialized to XML</param>
        /// <returns>XML string</returns>
        public String serializeObject(Object pObject)
        {
            try
            {
                String XmlizedString = null;
                MemoryStream memoryStream = new MemoryStream();
                XmlSerializer xs = new XmlSerializer(pObject.GetType());
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
                xs.Serialize(xmlTextWriter, pObject);
                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
                return XmlizedString;
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
                return null;
            }
        } 
        
        /// <summary>
        /// Method to reconstruct an Object from XML string
        /// </summary>
        /// <param name="pXmlizedString"></param>
        /// <returns></returns>
        public Object deserializeObject(String pXmlizedString)
        {
            XmlSerializer xs = new XmlSerializer(typeof(Object));
            MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
            XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
            return xs.Deserialize(memoryStream);
        } 

        /// <summary>
        /// To convert a Byte Array of Unicode values (UTF-8 encoded) to a complete String.
        /// </summary>
        /// <param name="characters">Unicode Byte Array to be converted to String</param>
        /// <returns>String converted from Unicode Byte Array</returns>
        private String UTF8ByteArrayToString(Byte[] characters)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            String constructedString = encoding.GetString(characters);
            return (constructedString);
        }
        
        /// <summary>
        /// Converts the String to UTF8 Byte array and is used in De serialization
        /// </summary>
        /// <param name="pXmlString"></param>
        /// <returns></returns>
        private Byte[] StringToUTF8ByteArray(String pXmlString)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            Byte[] byteArray = encoding.GetBytes(pXmlString);
            return byteArray;
        } 
    }
}


I then create a new instance of serializer and pass it my Changes object. I have debugged through the serialization code and that works fine, its right after where it fails with the same exception that the type "Changes" was not expected.

Any ideas anyone ?
Questionproblem with keypress function Pin
MehmetKocc22-Apr-09 3:57
MehmetKocc22-Apr-09 3:57 
AnswerRe: problem with keypress function Pin
musefan22-Apr-09 4:02
musefan22-Apr-09 4:02 
AnswerRe: problem with keypress function Pin
Luc Pattyn22-Apr-09 4:13
sitebuilderLuc Pattyn22-Apr-09 4:13 
AnswerRe: problem with keypress function Pin
DoctorMick22-Apr-09 4:15
DoctorMick22-Apr-09 4:15 
AnswerRe: problem with keypress function Pin
ramz_g22-Apr-09 23:22
ramz_g22-Apr-09 23:22 
QuestionRefreshing Windows Form content / moving the window around Pin
Piratenwichtl200022-Apr-09 3:40
Piratenwichtl200022-Apr-09 3:40 
AnswerRe: Refreshing Windows Form content / moving the window around Pin
musefan22-Apr-09 4:00
musefan22-Apr-09 4:00 
GeneralRe: Refreshing Windows Form content / moving the window around Pin
Piratenwichtl200022-Apr-09 21:24
Piratenwichtl200022-Apr-09 21:24 
QuestionHow can i perform Alt+T operation through programming in c#.net 3.5 Windows application. Pin
Narendra Reddy Vajrala22-Apr-09 3:35
Narendra Reddy Vajrala22-Apr-09 3:35 
AnswerRe: How can i perform Alt+T operation through programming in c#.net 3.5 Windows application. Pin
Henry Minute22-Apr-09 3:49
Henry Minute22-Apr-09 3:49 
GeneralRe: How can i perform Alt+T operation through programming in c#.net 3.5 Windows application. Pin
Narendra Reddy Vajrala22-Apr-09 5:08
Narendra Reddy Vajrala22-Apr-09 5:08 
GeneralRe: How can i perform Alt+T operation through programming in c#.net 3.5 Windows application. Pin
Henry Minute22-Apr-09 5:12
Henry Minute22-Apr-09 5:12 
AnswerRe: How can i perform Alt+T operation through programming in c#.net 3.5 Windows application. Pin
Luc Pattyn22-Apr-09 4:16
sitebuilderLuc Pattyn22-Apr-09 4:16 
Questioncan i rotate a panel and its content Pin
Babita Shivade22-Apr-09 3:00
Babita Shivade22-Apr-09 3:00 
AnswerRe: can i rotate a panel and its content Pin
Dave Kreskowiak22-Apr-09 6:38
mveDave Kreskowiak22-Apr-09 6:38 
Questioni am posting the same question here for reference for u peoples Pin
Hema Bairavan22-Apr-09 2:57
Hema Bairavan22-Apr-09 2:57 
AnswerRe: i am posting the same question here for reference for u peoples PinPopular
Pete O'Hanlon22-Apr-09 3:07
mvePete O'Hanlon22-Apr-09 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.