473,324 Members | 2,246 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,324 software developers and data experts.

Object "type not expected" when using serialization in web services

1
Hi all,

Hope I am posting this in the right forum.

I seem to be having a problem when using serialization and web services.

<b>Scenario:</b>

I have built a web service which includes a multitude of web methods. All the web methods have various parameters, but one parameter which they all have in common is an 'object' parameter. This is due to the fact that the web service works differently according to the type of object being passed into it.

Now as for the objects, I have constructed a set of custom classes which satisfy my need. For example's sake, let us say we have:

Teacher class
Student Class
LectureRoom Class
Lecture Class

We will call these the "School Package classes"

I am then wrapping these classes within other custom classes which I use not only to transport my objects around but also to keep track of statuses etc. Example:

Request Class
Response Class

The school package classes would be serialized and saved within the request or response class. So effectively, the objects which the web service really sees are the request and response classes which will in turn have the school package classes inside of them.

<b>The Problem:</b>

The problem is found when a school package object is passed within the response and request object. On deserialisation or transportation of these objects, the web service always throws an exception as follows:

{"System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type <CLASSNAME> was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

From what I could gather and the research I have done, the problem lies with the web service not knowing of the object types at compile time.

<b>Make Shift Solution:</b>
For a quick and dirty solution I created methods within the web service which use the object types needed. For Example:

public void Junk(Student myStudent){}

This seemed to have worked, but is not what I want, as with about 40 custom classes, this is both horrible coding and very tedious.

I have also tried researching the xmlinclude and soapinclude found in the System.Xml.Serialization library, but dont really know how to use these. I have tried adding them above the web service class declaration and the web methods which use the objects in this format:

[XmlInclude(typeof(Student))]

But yet to no avail. I have officially run out of ideas and would greatly appreciate anyone who has experience or ideas regarding this problem.

Thank you very much in advance for your time and excuse the length of the post.
Apr 22 '09 #1
0 2603

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Danny | last post by:
Hi I don't understand why I keep getting "Error: Object expected" I tried different things and haven't been able to solve it. I'm a newbie so I'm not sure what I'm doing wrong. The debugger breaks...
9
by: Arash Dejkam | last post by:
Hi All, Is it possible to write on an <OBJECT type="text/html"> using document.write() from within the html containing that tag the way we write on a popup window? I couldn't do that after a lot...
6
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> ...
2
by: Don | last post by:
Is there anyway to convert an object from one type to another using either a System.Type object containing the desired type to convert to or a string variable containing the name of the type to...
1
by: tilt | last post by:
Hello, I use an object element to replace the iframe element in ie, like this: <object id="x_obj" data="http://.../" type="text/html"> <iframe name="x_if" id="x_if"...
16
by: Steve Chapel | last post by:
When I load the page <https://bugzilla.mozilla.org/attachment.cgi?id=237739with Internet Explorer 7 RC 1, I get the error "Object Expected" at line 174. When I click on the button, I also get the...
1
by: monudjn | last post by:
Hi I am implementing ajax in portal. Using ajax i am able to updating the content of portlets asynchronously. However i am facing a problem The Problem: While submitting the form i am getting...
10
RMWChaos
by: RMWChaos | last post by:
WinVista/IE7 I am getting some weird errors only in IE7, but not in FF2.0.0.8 or NN9. It even happens on this website when I click "Sign In". The error is: "A Runtime Error has occurred."...
7
by: EdEvans | last post by:
have the following code on a page: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Page.ClientScript.RegisterStartupScript(this.GetType(), "DoPreview",...
2
by: jman | last post by:
i'm getting an "object expected" error in ie - not ff. in the BODY onload attribute i call a function that's loaded from an external file. i've narrowed the error down to the fact it cannot...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.