473,661 Members | 2,453 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.InvalidO perationExcepti on: 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 2329
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.co m

<ca**********@y ahoo.co.uk> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.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.InvalidO perationExcepti on: 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
3178
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 the Data Access Layer method -or- 2) Pass some kind of a unique id to the Data Access Layer method
7
4742
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 and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
25
5048
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 Logic Layer (BLL) and User Interface Layer (UIL). The problem I found with this was circular referencing...
0
1902
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 control. In a default.aspx page <SkinExample:Hello id="HelloControl" SkinName="red" runat="server" /> i can pass the value, it works fine, but from the dropdownlist in a codebehind page i can't pass the value. Could some one help me out with...
6
3248
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 query-string flag is used to indicate to the page whether it should instantiate a new instance of the object or access an existing instance from the calling page. On the both pages I have a property of the page which is an instance of this custom...
12
5323
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 the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
9
3784
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 techniques are not feasible) The question is; Given that I have a Person object with a private set for id. What is the recommended approac in passing that object to the web service
8
8895
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 webmethod1(object a) where a can be of type string, DateTime, float, etc..
2
4271
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 Property1 As String Public Property2 As Integer Public Property myCollection1 As Arraylist (Actually, it will be a strongly
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8855
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8758
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7364
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
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 we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.