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

Can a web method return an instance of an interface?

Hello,

I trying to determine whether or not it is possible to create a
web service whose methods are declared to return interfaces. I have
been researching it and have found lots of hints and clues. I even
read a post from a Microsoft employee (dated 2004) that said it was
not possible - but I am not convinced.

For instance the following web method works (i.e. the code builds
and the method can be invoked via Internet Explorer):

[WebMethod]
public IList GetList()
{
IList theList = new ArrayList();
theList.Add("My Item");
return theList;
}

However the following web method does not work:

[WebMethod]
public IUser GetUser()
{
return new User("John", "Smith");
}

So, the framework class library's IList interface and ArrayList
implementation must "know" something that my custom IUser interface
and User implementation do not.

I decided not to clutter my post with gobs of code and exceptions. I
am experimenting with various things such as having my User class
implement IXmlSeriablizable - I will continue to work on it. The main
thing that I would like to know is: Am I headed down a dead end road?

Any feedback will be greatly appreciated.

Regards,

R. Vaessen

Mar 17 '07 #1
3 2928
<ro****@rvaessen.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
Hello,

I trying to determine whether or not it is possible to create a
web service whose methods are declared to return interfaces. I have
been researching it and have found lots of hints and clues. I even
read a post from a Microsoft employee (dated 2004) that said it was
not possible - but I am not convinced.

For instance the following web method works (i.e. the code builds
and the method can be invoked via Internet Explorer):

[WebMethod]
public IList GetList()
{
IList theList = new ArrayList();
theList.Add("My Item");
return theList;
}

However the following web method does not work:

[WebMethod]
public IUser GetUser()
{
return new User("John", "Smith");
}

So, the framework class library's IList interface and ArrayList
implementation must "know" something that my custom IUser interface
and User implementation do not.
Well, someone "knows".

I suspect there is Schema Importer Extension magic going on here similar to
what happens in .NET 2.0 with typed datasets.

John
Mar 17 '07 #2
Hi,
As far my understanding goes one can return custom types from web
services.Only thing is that whatever you returm must be serializable.Yoc can
enable seriazation by using XMLInclude attribute.Find below a link which will
provide you insights/ideas in this area.
http://www.dalepreston.com/Blog/2005...-from-web.html
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"ro****@rvaessen.com" wrote:
Hello,

I trying to determine whether or not it is possible to create a
web service whose methods are declared to return interfaces. I have
been researching it and have found lots of hints and clues. I even
read a post from a Microsoft employee (dated 2004) that said it was
not possible - but I am not convinced.

For instance the following web method works (i.e. the code builds
and the method can be invoked via Internet Explorer):

[WebMethod]
public IList GetList()
{
IList theList = new ArrayList();
theList.Add("My Item");
return theList;
}

However the following web method does not work:

[WebMethod]
public IUser GetUser()
{
return new User("John", "Smith");
}

So, the framework class library's IList interface and ArrayList
implementation must "know" something that my custom IUser interface
and User implementation do not.

I decided not to clutter my post with gobs of code and exceptions. I
am experimenting with various things such as having my User class
implement IXmlSeriablizable - I will continue to work on it. The main
thing that I would like to know is: Am I headed down a dead end road?

Any feedback will be greatly appreciated.

Regards,

R. Vaessen

Mar 18 '07 #3
On Mar 17, 4:57 pm, "John Saunders" <john.saunders at trizetto.com>
wrote:
<rob...@rvaessen.comwrote in message

news:11**********************@n59g2000hsh.googlegr oups.com...
Hello,
I trying to determine whether or not it is possible to create a
web service whose methods are declared to return interfaces. I have
been researching it and have found lots of hints and clues. I even
read a post from a Microsoft employee (dated 2004) that said it was
not possible - but I am not convinced.
For instance the following web method works (i.e. the code builds
and the method can be invoked via Internet Explorer):
[WebMethod]
public IList GetList()
{
IList theList = new ArrayList();
theList.Add("My Item");
return theList;
}
However the following web method does not work:
[WebMethod]
public IUser GetUser()
{
return new User("John", "Smith");
}
So, the framework class library's IList interface and ArrayList
implementation must "know" something that my custom IUser interface
and User implementation do not.

Well, someone "knows".

I suspect there is Schema Importer Extension magic going on here similar to
what happens in .NET 2.0 with typed datasets.

John
John,

I suspect that you are correct - the framework "knows" about its
own classes.

Thanks!

R.V.

Mar 18 '07 #4

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

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
18
by: Daniel Gustafsson | last post by:
Hi there, hmm, I've just started with C# and I'm experimenting with method overloading. It seems like it's not possible to override method using return types, only parameters. Is that by design,...
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
1
by: Steven.Xu | last post by:
Hi every one. I have two class: MyBase and MySon. MyBase is the base class of MySon. On the other hand I have two interface: MyBaseItef and MySonItef. MyBaseItef is the base interface of...
10
by: Mark | last post by:
I have an abstract class, and a set of classes that inherit from my abstract class. The fact that it is abstract is likely irrelevant. I have a static factory method in my abstract class that...
11
by: Andy | last post by:
Make the story short, I have a VB.NET client interface calling .NET webservice, written in VB.NET as well. I am trying to make the client as thin as possible so I let the webservice part to...
26
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
12
by: jeremito | last post by:
Please excuse me if this is obvious to others, but I can't figure it out. I am subclassing dict, but want to prevent direct changing of some key/value pairs. For this I thought I should override...
15
by: Sunburned Surveyor | last post by:
I'm a Java developer in the process of writing a class library in C#, so please bear with me. I'm trying to write a method that can return a generic Object OR a Decimal value. In Java I would...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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: 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: 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....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
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...

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.