473,508 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a custom object via a web method

I have a web service which exposes a method...

[WebMethod]
public Object Invoke(Object obj)
{
...
}

both the input param and the return value objects can, in reality, be
anything. Howver, if I call this method from a client and cast my own
custom object as Object, I get this error...

System.InvalidOperationException: The type MyType was not expected. Use
the XmlInclude or SoapInclude attribute to specify types that are not
known statically.

My custom class is defined like this...

[XmlInclude( typeof( MyType ) )]
public class MyType
{
...
}

Obviously I need to do more, but what?

Cathy

Mar 8 '06 #1
2 2322
Cathy,

It's almost impossible to do this with a WebMethod. Ideally, the way
that this would translate into WSDL would be that the parameter and the
return value would allow any valid XML. This would also mean that you have
to process the XML yourself to interpret the contents correctly.

Basically, this kind of design is not recommended. You are better off
creating more strongly typed versions, or rather, expose XML as the inputs
and/or outputs and do some pre-post processing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<ca**********@yahoo.co.uk> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
I have a web service which exposes a method...

[WebMethod]
public Object Invoke(Object obj)
{
...
}

both the input param and the return value objects can, in reality, be
anything. Howver, if I call this method from a client and cast my own
custom object as Object, I get this error...

System.InvalidOperationException: The type MyType was not expected. Use
the XmlInclude or SoapInclude attribute to specify types that are not
known statically.

My custom class is defined like this...

[XmlInclude( typeof( MyType ) )]
public class MyType
{
...
}

Obviously I need to do more, but what?

Cathy

Mar 8 '06 #2
Hi Nicholas,

Many thanks for your reply, but obviously your understanding far
outstrips mine. You say 'expose XML as the inputs and outputs...
pre-post processing'. Could you please be a bit more specific?

BTW, I've just come from a Java servlet/applet/browser environment and
I'm exploring the possibility of moving our app to C# with a ClickOnce
client talking to a webservice.

Cathy

Mar 9 '06 #3

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

Similar topics

11
3160
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
7
4732
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
25
5024
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business...
0
1892
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
6
3242
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
12
5292
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
9
3771
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
8
8886
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I'm trying to pass values of different data-types to a web-service. I thought it would be easier to box these values and pass them as a System.object parameter, like public void...
2
4266
by: =?Utf-8?B?Y3Nz?= | last post by:
I am new to ASP.net webservice and have a quesiton. Is is possible to pass custom object to a web service (using VB 2005)? My custom object will look like this Public Class Myclass Public...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.