|
System.Runtime.Serialization is used for binary serialization.
Since Webservices use Soap wich is xml, you should serialize objects to xml.
Read this article on msdn about XML Serialization with XML Web Services.
In your example, just import System.Xml.Serialization and add the annotation [System.Xml.Serialization.XmlTypeAttribute()].
And make public accessors to the members you want to be serialized.
using System;
using System.Runtime.Serialization;
using Person;
using System.Xml;
using System.Xml.Serialization;
namespace SchoolPackage
{
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.x.com/namespace/", TypeName = "Student")]
public class Student
{
[System.Xml.Serialization.XmlElementAttribute(ElementName = "myCustomXmlElementName")]
public string StrLastAlteredByUser
{
get { return strLastAlteredByUser; }
set { strLastAlteredByUser = value; }
}
}
}
ps. personally I would let Student inherit Person
|
|
|
|
|
I have done as you suggested and am still getting the same error. The problem now I believe is the way I am serialising the object. I have made a custom class for this:
using System;
using System.Text;
namespace Helper
{
public class Serializer
{
public Serializer()
{
}
///
/// Method to deserialise an object from a string of hex characters
///
/// <param name="hex" />
/// <returns>the object which was deserialised
public Object DeserialiseObject(String hex)
{
System.IO.MemoryStream stream2;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter2
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
byte[] array = HexStringToByteArray(hex);
stream2 = new System.IO.MemoryStream(array);
Object obj = bformatter2.Deserialize(stream2);
stream2.Close();
return obj;
}
///
/// Method to serialise an object into a hex string
///
/// <param name="temp" />
/// <returns>
public string serializeObject(Object temp)
{
//write it to stream
System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter2
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bformatter2.Serialize(stream2, temp);
byte[] array = new byte[stream2.Length];
array = stream2.ToArray();
String hex = ByteArrayToHexString(array);
stream2.Close();
return hex;
}
///
/// Helper to change a byte array to a hex string
///
/// <param name="Bytes" />
/// <returns>string of hex characters
private static string ByteArrayToHexString(byte[] Bytes)
{
StringBuilder Result;
string HexAlphabet = "0123456789ABCDEF";
Result = new StringBuilder();
foreach (byte B in Bytes)
{
Result.Append(HexAlphabet[(int)(B >> 4)]);
Result.Append(HexAlphabet[(int)(B & 0xF)]);
}
return Result.ToString();
}
///
/// Helper to change hex string to byte array
///
/// <param name="Hex" />
/// <returns>returns a byte array
private static byte[] HexStringToByteArray(string Hex)
{
byte[] Bytes;
int ByteLength;
string HexValue = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9|||||||\xA\xB\xC\xD\xE\xF";
ByteLength = Hex.Length / 2;
Bytes = new byte[ByteLength];
for (int x = 0, i = 0; i < Hex.Length; i += 2, x += 1)
{
Bytes[x] = (byte)(HexValue[Char.ToUpper(Hex[i + 0]) - '0'] << 4);
Bytes[x] |= (byte)(HexValue[Char.ToUpper(Hex[i + 1]) - '0']);
}
return Bytes;
}
}
}
|
|
|
|
|
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()
{
}
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;
}
}
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);
}
private String UTF8ByteArrayToString(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedString = encoding.GetString(characters);
return (constructedString);
}
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 ?
|
|
|
|
|
Hi
What i need to do is to get keyboard letters and "letter combinations" which is the core of my problem
for ex:
when i press alt + f4 i wnat to see alt f4 in the label
i have the code snippet
protected override void OnKeyDown(KeyEventArgs keyEvent)
{
label1.Text = "";
label1.Text=keyEvent.KeyCode.ToString();
}
Can anyone show me a way to do it please?
Thanks...
|
|
|
|
|
hmmmm seems suspicious... but I think KeyEventArgs has something to detect if buttons like alt, shift, ctrl are currently pressed.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
forget the loop, loops seldom belong in an event handler.
Create one method that is used for both KeyDown and KeyUp events.
|
|
|
|
|
Check the value of keyEvent.Alt, it will be true if the alt key is held down.
|
|
|
|
|
Hi,
You can override the ProcessCmdKey() function in Control class like this :
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Alt | Keys.F4))
{
//Your Code
}
return base.ProcessCmdKey(ref msg, keyData);
}
Hope this helps,
ramz_g
|
|
|
|
|
Hi guys,
I am facing the following problem:
my application is downloading large chunks of data and informs the user about it (how many bytes of total bytes... how many % already loaded and so on).
this work is done by a component that informs the form by rasing a event. within the method which gets executed by the event happens a updatePanel.Refresh() (a redraw of the panel that shows the information)
because that event gets fired reasonable often, the updatePanel is redrawn all the time.
when I try to move the windows of the application it doesnt work properly.
what must I do to stop the refresh of the updatePanel when the form is moved around?
any suggestions welcome
thansk
best regards
t
|
|
|
|
|
well for one I assume the work is being done on a separate thread?
You could try limiting the update with a timer or counter...
for example if your updating with every downloaded byte of data you could update with every KB of data, or you could use a timer and then update only if a certain period has elapsed, then reset the timer with each update.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi mate,
thanks for sharing your idea. helped me impementing a quick solution to the problem.
basically, i use a timer and the forms-move event. i start the timer when the form is moved and let the timer point to a method whichs sets a flag, that the form is on the move. works like a charm.
thanks
best regards
t
|
|
|
|
|
Hi,
How can i perform Alt+T operation through programming in c#.net 3.5 Windows application.
Thanks In Advance
--Naren
|
|
|
|
|
That would depend on what Alt-T does in your application.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to open a topic using that
|
|
|
|
|
I am sorry, but you are using terminology with which I am not familiar.
What is a 'topic'?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
there are two easy ways:
1. create a menu item that does what you want ALT+T to do, then assign it ALT+T as a shortcut.
or
2. handle KeyDown (or KeyPress) event, check for the right key combination, and act on it.
|
|
|
|
|
hi all,
i m making a windows application in C#. i want to rotate a panel in this panel i am capturing a video, i want to rotate this panel so the video is also rotate with this panel can any one help me...
thanks in advance..
|
|
|
|
|
Not easily, no. The Panel control doesn't directly support being rotated to an arbitrary angle. WPF, on the other hand, will allow you to do this and render video in it. I suggest picking up a beginners book on WPF before proceeding. It's got quite a steep learning curve.
|
|
|
|
|
Hi peoples,
I am working in WPF screen,
i need to clear all the controls(values) in the screen at one stretch,
if win forms we can give as (foreach control in this.controls)
but here how can we do??
|
|
|
|
|
First of all, this is a WPF question.
Second, people here don't get paid to answer questions, so they may take some time to get to your question.
Third, it's bad form to repost a question just to bump it. It makes it less likely that you'll get an answer.
Fourth. I was writing a sample of the code for you to demonstrate how to do this, but now I don't want to finish it. You lost me when you posted this question.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
hi mr Pete O hanlon,
Actually, i didn't put again to bump my question here,and also i know that no body is getting paid for reply.
i already put the same in WPF message board, but i saw for the past two hours no reply for that..
but here in C# board lot of replies are coming, i thought no body is going for WPF forum,
so only i re posted here that's all.
|
|
|
|
|
Need 2 hour turnaround on your question? Pay someone to answer it. Otherwise, just wait patiently like everyone else does!
|
|
|
|
|
i dont want to give reply for ur post in common forum....
|
|
|
|
|
I have entered one question regarding WPF screen,in WPF message board, can any one reply for that?
|
|
|
|
|
yeah anyone that is a CodeProject member can reply to it. I would say wrong forum but i dont think there is a forum for question about who can reply to other questions...
Perhaps you should put in a request for one
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|