|
I was hoping there was simply a setting on the serialization engine, but I guess this will do (using IXmlSerializable... ISerializable didn't work for me). I am slightly concerned, however, since a client needs my deserializer on the other side. I will have to try to mimick the auto-generated xml so a C# programmer can interface with my web service using only the WSDL. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
How come ISerializable does not work for you?
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
I don't know, but when I implemented that interface (and the corresponding constructor), nothing changed. The code within those methods was never executed. I am serializing these objects to/from a web service, which is apparently different from other methods of serialization. Almost everyone who has given me serialization advice tells me the same thing you told me, so I must be implementing the uncommon case or something. Anyway, thanks again for the help,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Ok, I understand. ISerializable is for binary serialization.
For XML, what you could do is implement properties and decorate them with the attributes of the System.Xml.Serialization namespace. For instance, suppose you want to serialize an enum into an hexadecimal string:
<code>
public class MyClass
{
public enum SomeEnum
{
EnumValue1 = 1,
EnumValue2 = 2
}
private SomeEnum _myEnum = SomeEnum.EnumValue1;
[XmlElement(ElementName="MyEnum")]
public string MyEnumAsHexString
{
get
{
return String.Format("{0:X}", (int)this._myEnum);
}
set
{
int enumValue = Int32.Parse(value, NumberStyles.AllowHexSpecifier);
this._myEnum = (SomeEnum)enumValue;
}
}
[XmlIgnore]
public SomeEnum MyEnum
{
get
{
return this._myEnum;
}
set
{
this._myEnum = value;
}
}
}
</code>
So, in the example above, your web service will serialize only the hexadecimal string property because the other one is tagged with [XmlIgnore].
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Yeah, I thought about doing that, but didn't like the fact that it no longer contained information about the type. Clients (of my WS) would see a string that looks like hex, but maybe it is a GUID without the slashes, or an IPv6 ip address without the colons... you get the idea. I was hoping there was an attribute to tell the serializer, "I have this enum that I want you to pass by hex value", then clients on the receiving end would get the type as enum and it would deserialize appropriately. Anyway, I came up with a different (probably better) way of doing what I was attempting to do (combining multiple fields into a single flags value). Instead of combining fields in a cryptic way for the end user of my service, I simply serialize a more verbose object back, splitting the fields into their own properties. The following illustrates this:
public enum Language {
Spanish = 1,
English = 2,
}
public enum Country {
USA = 1,
DEU = 2,
}
public class CountryAndLanguage { ... }
The reason I was attempting the first way was because I was misinformed that I could not return abstract types from a web service. Therefore, I thought that I had to have a concrete return type that would hold all the information contained within all derived types. This is incorrect, which is why I am now using the "correct" way of doing this mentioned above. Thanks again for the help,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I don't know if this will work with SOAP, but you get the idea: A property that is used for serialization and another that is used in C# code.
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Hi all! How i can to invoke SQL Function through SqlCommand class,
what syntax i should use in CommandText and what value i should define in CommandType
THANK
|
|
|
|
|
Are you using an Article or tutorial? If not you should, there are many Database related articles here on Code Project. Use the Site Menu on the left side of the page to find them.
|
|
|
|
|
For scalar UDFs (which return a single value) use:
select dbo.MyUdfName()
For table-valued UDFs (that return a resultset) use:
select * from dbo.MyUdfName()
Regards
Andy
|
|
|
|
|
Hi all
I would like to trigger a function (writing a time stamp)
when Visual Studio is running in Debug Mode and an exception is thrown by the code.
I am basically interested in the event OnExceptionRaised in Visual Studio.
I saw that there is some DebuggerEventClass but it is something internal that cannot be used.
Is there any way to do that? I noticed that VIsualStudioIDE supportsa COM component model
but I think that this is not also supported.
Kind Regards
ManuStone
|
|
|
|
|
Hi,
I have an mdi parent form (frmMain) and a child form (frmChild)
Using c#, How is it possible to set the height of the child form as long as that in the frmMain i.e. the parent form.
At present the frmChild appears in the middle of frmMain but there is room for the frmChild's height to be increased.
Tried frmChild.height but .height does not appear in the intellisense.
Thanks
|
|
|
|
|
A form has a Size property.
ChildForm child = new childForm();
child.MdiParent = this;
child.Size = new Size(this.Width, this.Height);
child.Show();
This will set the height and width of the child form to be the same as its parent form.
|
|
|
|
|
I get a scrollbar on the parent form because the child form seems to be too long.
Any thoughts please?
This is what I have
Form frmNew = new frmChild();
frmNew.MdiParent = this;
frmNew.Size = new Size(frmNew.Width, this.Height);
frmNew.Show();
|
|
|
|
|
frmNew.Size = new Size(frmNew.Width, this.ClientSize.Height);
|
|
|
|
|
That still gives a scrollbar.
|
|
|
|
|
Wierd, I'm sure that's how I've done it before!
This way works if you want width and height:
In your child form's load event put...
this.Dock = DockStyle.Fill;
|
|
|
|
|
It depends how you will use your child form. I cant seem to get the child form to appear within the client rectangle without scroll bars apart from hacking it. So here is a couple of options you could have a look at.
1. You can set the child forms Dock = Fill.
2. You can set the child forms WindowState = FormWindowState.Maximized.
3. You can set the childs size to parentForm.ClientRectangle - x. (hack i know)
Sorry I am all out of ideas after that. The scroll bars seem to appear no matter if i set the hscroll etc props.
|
|
|
|
|
Solved it by doing this:
frmNew.Size = new Size(frmNew.Width, this.Height - 80);
Thanks
|
|
|
|
|
You may want to check the value of this.Height before you run this line of code. Setting the size to a negative number could be detrimental to the execution of your application.
|
|
|
|
|
Ok, I've checked the code that I used in a previous project and this works fine:
this.Height = this.Parent.ClientSize.Height;
Using this.MdiParent.ClientSize.Height doesn't however - strange!
|
|
|
|
|
Is there any code in C# to get GUID of network card.
Thanks.
The great pleasure in life is doing what people say you cannot do.
|
|
|
|
|
GUID of network card? Do you mean the Mac Address? If so, you can use WMI to retrieve it:
public string GetMACAddress()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string address = string.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == string.Empty)
{
if ((bool)mo["IPEnabled"] == true)
address = mo["MacAddress"].ToString();
}
mo.Dispose();
}
address = address.Replace(":", string.Empty);
return address;
}
|
|
|
|
|
Thanks Pete O'Hanlon for your reply, but i need GUID which also called UUID.
Any Idea please.
The great pleasure in life is doing what people say you cannot do.
|
|
|
|
|
Hi,
I have recently got a test server running so the employees can input test data without needing worry about if they mess up.
So I written a small c# windows app that the user runs and it has two buttons "test server" or "live server".
The problem is I want to indicate to the user what system they are in, but I cant mod the exe so can I execute the exe within a windows form app, so the exe is contained inside the windows form and I can place some text on the Form like "You are in the Test Server",
how can I get the exe to load within a form?
|
|
|
|
|
What you would have to do is set the form so that it is MDI and then use WinAPI to get the handle of the main form for the application you want to embed and set its parent (done through API) to the .NET application that you are developing.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|