473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IXmlSerializable: return type & difference IE / webservice

Hello all,

I'm using the IXmlSerializable interface for a project and encounter some
problems when testing my webservice in a client application. I know this
interface is undocumented and not intended for use, but I think this is the
only solution for my situation. I searched the web, in the hope finding the
answer, without any luck, so my final hope is with you.

Let me explain the situation:
I have an 'export'-wrapper to my regular objects. For each regular object
there is also an export object. An export object derives from the regular
object and has for each property in the base object an extra boolean
property. That extra property tells wether to include the base property in
the final export (= webservice) or not. That is because not all the
properties may be exposed all the time (depending on who is requesting it).
To implement this I have used the IXmlSerializable interface on the export
objects. Another reason I used the IXmlSerializable interface is that I can
choose the xml element names, especially for the collections (so I don't get
ArrayOf.....). The webservice returns export collection objects (implementing
IXmlSerializable).

To test my webservice I created a simple WinForms application which calls
one of the webmethods. But when adding the Web Reference to my test
application the proxy is not well generated. The return type of the webmethod
is not my export collection type, but a DataSet. I can work around that issue
if I let my webmethod only return a 'single' object instead of a collection:
I just changed the return type in the generated proxy to my custom collection
type. But then I needed to add an extra reference to my project; that is a
reference to the assambly which holds the export objects.

I've tried the same thing to return my custom collection, but that does not
work unless I do not implement the IXmlSerializable interface on the
collection. If I do that, I lose the ability to choose a custom xml element
name. When I implement the IXmlSerializable interface I get this error:
An unhandled exception of type 'System.InvalidOperationException' occurred
in system.web.services.dll
Additional information: Method Export.GetTest can not be reflected.

I do not understand why this does not work. I get the correct results when I
open the .asmx page in Internet Explorer, even with the IXmlSerializable
interface implemented on the collections. If it works in IE, why does it not
work when generating the proxy? Does someone knows what is going wrong here
or what I am doing wrong? This problem holds me from going to the next phase
of the project. Any help is appreciated!

Below you can find a stripped code example of my situation.
Thanks in advance and best regards,
Thomas

My code:
---------------------------
I have stripped down the code here for simplicity. My export class does not
derive from any base class, nor does it have the booleans. However when I try
the code below I still have the same problem.
// this is the export object which normally derives from 'Test'.
[Serializable]
public class TestExport : IXmlSerializable
{
private string name;
private string email;

public TestExport()
{
}

public string Name
{
get { return name; }
set { name = value; }
}

public string Email
{
get { return email; }
set { email = value; }
}

#region IXmlSerializable
public XmlSchema GetSchema()
{
return null;
}

public void ReadXml(XmlReader reader)
{
// Read the opening tag of the encapsulating element
reader.ReadStartElement();

// Open the root element for our object
reader.ReadStartElement("Test");

reader.ReadStartElement("Name");
this.Name = reader.ReadString();
reader.ReadEndElement();

reader.ReadStartElement("Email");
this.Email = reader.ReadString();
reader.ReadEndElement();

// Close the root element for our object
reader.ReadEndElement();

// Read the end tag of the encapsulating element
reader.ReadEndElement();
}

public void WriteXml(XmlWriter writer)
{
writer.WriteStartElement("Test");
writer.WriteElementString("Name", this.Name);
writer.WriteElementString("Email", this.Email);
writer.WriteEndElement();
}
#endregion
}
[Serializable]
public class TestenExport : CollectionBase, IXmlSerializable
{
public TestenExport()
{
}

#region IXmlSerializable
public XmlSchema GetSchema()
{
return null;
}

public void ReadXml(XmlReader reader)
{
// Read the opening tag of the encapsulating element
reader.ReadStartElement();

// Open the root element for our object
reader.ReadStartElement("Tests");

foreach(TestExport item in this)
{
item.ReadXml(reader);
}

// Close the root element for our object
reader.ReadEndElement();

// Read the end tag of the encapsulating element
reader.ReadEndElement();
}

public void WriteXml(XmlWriter writer)
{
writer.WriteStartElement("Tests");
foreach(TestExport item in this)
{
item.WriteXml(writer);
}
writer.WriteEndElement();
}
#endregion

#region CollectionBase
public int Add(TestExport @value)
{
return List.Add(@value);
}

public TestExport this[int index]
{
get
{
return (TestExport)(List[index]);
}
set
{
List[index] = value;
}
}
#endregion
}

Nov 23 '05 #1
1 4386
[SNIP]
I've tried the same thing to return my custom collection, but that does not
work unless I do not implement the IXmlSerializable interface on the
collection. If I do that, I lose the ability to choose a custom xml element
name. When I implement the IXmlSerializable interface I get this error:
An unhandled exception of type 'System.InvalidOperationException' occurred
in system.web.services.dll
Additional information: Method Export.GetTest can not be reflected.


I have found the problem for this. My ReadXml() method in the collection was
not correct. Here is what I use now:

public void ReadXml(XmlReader r)
{
r.Read(); // move past container
r.ReadStartElement("Testen");
while (r.NodeType != XmlNodeType.EndElement)
{
r.ReadStartElement("Test");
string name = r.ReadElementString("Name");
string email = r.ReadElementString("Email");
string company = r.ReadElementString("Company");
r.ReadEndElement();
this.Add(new TestExport(name, email, company));
}
r.ReadEndElement();
}

I still need to add a reference to my 'Export objects'-assembly and manually
change the return types in the proxy. The proxy does not recognize the used
types itself! This means I will need to manually change the proxy each time
the webservice changes. Anyone has a solution for this?
Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Leepe | last post by:
example: I have a skill object that implements the XmlSerializable interface Implementing the getschema gives me some unwanted generations towards the wsdl.exe Reference.cs generation. skill is...
1
by: mattoc | last post by:
Happy new year to all. I have a strange error that I've been trying for a while now to fathom.. Basically I have a hierarchy of state classes that I need to serialize to XML. Some of them can...
0
by: Thomas D. | last post by:
Situation: --------------------------- I have an 'export'-wrapper to my regular objects. For each regular object there is also an export object. An export object derives from the regular object...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
0
by: Dave Johnson | last post by:
My ASP.net 1.1 online cinema reservation system is Developed in 3 Tiers: 1-DataAccessTier "Data Repository Class" 2-Business Tier "Set of Business Classes" 3-Presentation Tier "set of...
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
3
by: John Glover | last post by:
To whoever can help, I've been having a problem with XML deserialization lately. I needed to serialize and deserialze two objects which inherited from Hashtable. Because IDictionary...
0
by: burningmidget | last post by:
I am having trouble using IXmlSerializable within a base class and having xsi:type work correctly when deserializing an xml file. Here is a very simplified version of the what is going on in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.