473,383 Members | 1,748 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,383 software developers and data experts.

Passing class with methods to a WS. Data not methods serialized

Hi,
In the WS I've defined a class that contains both data and methods. I'm
trying to pass this class to a client application using a web method. When I
access this class on the client only the properties are available not the
methods. I guess this makes sense but how can I get access/instantiate to
the complete class containing both the data and the methods?
Thanks,
Terry

Sep 22 '06 #1
5 1120
"twahl" <tw***@discussions.microsoft.comwrote in message
news:B0**********************************@microsof t.com...
Hi,
In the WS I've defined a class that contains both data and methods. I'm
trying to pass this class to a client application using a web method.
When I
access this class on the client only the properties are available not the
methods. I guess this makes sense but how can I get access/instantiate to
the complete class containing both the data and the methods?
You can't. Web Services don't work that way.

What happens is that there is a class on the server. For the sake of
discussion, let's call it "Employee". Emplyee has properties like ID and
Name and DateOfBirth. It has methods like Hire and Fire and Pay.

The client calls an operation on your web service, and you want to send an
Employee back. Your web service acquires an instance of the Employee class.
This instance gets serialized into the response to the web service
operation.

All that gets serialized is the data. Only XML, which conforms to the schema
which is a part of the WSDL file describing your web service.

The client receives this XML. Most clients will deserialize this into an
instance of a class, which may happen to be called "Employee". That need not
be the case. The client platform could choose to use a class called
WEBSERVICEMPLOYEE if it likes. It's also useful to keep in mind that not all
clients are object oriented!

All the client was sent was XML. The most the client can receive is data
which is deserialized from this XML. No methods were transmitted, so none
were received!

If you need your .NET Client and .NET Server to use the actual, identical
class, then you need to use .NET Remoting, not Web Services.

John
Sep 22 '06 #2
Hi John,
Thanks again for the help! Your explanation helped a lot.

If I have a web method returning an object that I wish to deserialize it to
an instance of a class? If possible can you provide an example in code as to
how I would do that or possibly point me to location that I can read up on it?

Thanks again,
Terry
"John Saunders" wrote:
"twahl" <tw***@discussions.microsoft.comwrote in message
news:B0**********************************@microsof t.com...
Hi,
In the WS I've defined a class that contains both data and methods. I'm
trying to pass this class to a client application using a web method.
When I
access this class on the client only the properties are available not the
methods. I guess this makes sense but how can I get access/instantiate to
the complete class containing both the data and the methods?

You can't. Web Services don't work that way.

What happens is that there is a class on the server. For the sake of
discussion, let's call it "Employee". Emplyee has properties like ID and
Name and DateOfBirth. It has methods like Hire and Fire and Pay.

The client calls an operation on your web service, and you want to send an
Employee back. Your web service acquires an instance of the Employee class.
This instance gets serialized into the response to the web service
operation.

All that gets serialized is the data. Only XML, which conforms to the schema
which is a part of the WSDL file describing your web service.

The client receives this XML. Most clients will deserialize this into an
instance of a class, which may happen to be called "Employee". That need not
be the case. The client platform could choose to use a class called
WEBSERVICEMPLOYEE if it likes. It's also useful to keep in mind that not all
clients are object oriented!

All the client was sent was XML. The most the client can receive is data
which is deserialized from this XML. No methods were transmitted, so none
were received!

If you need your .NET Client and .NET Server to use the actual, identical
class, then you need to use .NET Remoting, not Web Services.

John
Sep 22 '06 #3
"twahl" <tw***@discussions.microsoft.comwrote in message
news:68**********************************@microsof t.com...
Hi John,
Thanks again for the help! Your explanation helped a lot.

If I have a web method returning an object that I wish to deserialize it
to
an instance of a class? If possible can you provide an example in code as
to
how I would do that or possibly point me to location that I can read up on
it?
public class Employee
{
protected DateTime _fireDate;

public int ID {get {return _id;}}
public string Name {get {return _name;}}
public DateTime BirthDate {get {return _date;}}
public DateTime TerminationDate {get {return _fireDate;}}
}

public class EmployeeWithMethods : Employee
{
public void Fire() {_fireDate = DateTime.Now;}
}
John
Sep 23 '06 #4
Hi John,
How would I deserialize this class in a web method? This is my biggest area
of confusion. Again thanks for your help!
Terry
"John Saunders" wrote:
"twahl" <tw***@discussions.microsoft.comwrote in message
news:68**********************************@microsof t.com...
Hi John,
Thanks again for the help! Your explanation helped a lot.

If I have a web method returning an object that I wish to deserialize it
to
an instance of a class? If possible can you provide an example in code as
to
how I would do that or possibly point me to location that I can read up on
it?

public class Employee
{
protected DateTime _fireDate;

public int ID {get {return _id;}}
public string Name {get {return _name;}}
public DateTime BirthDate {get {return _date;}}
public DateTime TerminationDate {get {return _fireDate;}}
}

public class EmployeeWithMethods : Employee
{
public void Fire() {_fireDate = DateTime.Now;}
}
John
Sep 26 '06 #5
"twahl" <tw***@discussions.microsoft.comwrote in message
news:C6**********************************@microsof t.com...
Hi John,
How would I deserialize this class in a web method? This is my biggest
area
of confusion. Again thanks for your help!
Terry
Yeah, that's a good point. Sometimes I revert to my roots in C/C++, where
such things are only a cast away.

There is probably something that can be done using attribtues on the method
parameters, to tell .NET that when it sees a certain XML Element, it should
deserialize it to a particular class. But I don't know which attribute this
would be (maybe XmlElementAttribute or XmlTypeAttribute).

If that doesn't help, I'd personally punt and use delegation. I'd have my
EmployeeWithMethods class contain an instance of the deserialized class, and
just delegate all of the properties to this instance.

John
Sep 26 '06 #6

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

Similar topics

3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
3
by: GoodMorningSky | last post by:
I have long term question about object serialization. Object serialization is used in many ways. In .net I heard XML is used for object serialization. I understand how object values are serialized...
5
by: hellrazor | last post by:
Hi there, I'm very new to dot net programming and webservices programming. I've managed to create simple webservices so far. Here's my problem: -I've been given a project which needs to...
4
by: Sahil Malik [MVP] | last post by:
Okay so now I understand (surprised though) - that WebServices can indeed pass ByRef/ref parameters. All I have to do is mark an integer parameter of a WebMethod as "ref". Funnily enough, this is...
7
by: Peter | last post by:
I want to create a multidemensional arraylist. Seeing as they don't exist I was wondering if there is a way to create a class that works like one. I basically want to use it like this Dim...
12
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...
10
by: Stan | last post by:
There are two ways to pass structured data to a web service: xml === <Order OrderId="123" OrderAmount="234" /> or class =====
9
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
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...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.