473,608 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning an Object which inherits interface with a web service

I would like to return an object which inherits an interface. A web service
instantiate a class that inherits that interface and returns that object. But
I get error when referencing the web service from windows form. the error is:
"System.NotSupp ortedException: Cannot serialize interface
EmployeeCommon. IEmployee."

EmployeeCommon. IEmployee is an interface which is inerited by the
instantiated class. That class is instantiated and returned by the web
service called CompanySystem using a method called CreateEmployeeS ystem()
that returns IEmployee . IEmployee is inherited by the class Employee.

Here are the codes for what I am doing:

/*INTERFACE: this code is done in a common.dll project*/
public interface IEmployee
{
String GetName();
Int32 GetID();
}

/////There Codes are done in a web service project
/*CLASS EMPLOYEE TO INHERIT IEMPLOYEE*/
//I have removed System.Web.Serv ices.WebService
public class Employee :IEmployee
{
public Employee()
{}
.....implements all the interface methods
}
public class CompanySystem : System.Web.Serv ices.WebService
{
public CompanySystem()
{}
[WebMethod] //return I employee
public IEmployee CreateEmployeeS ystem()
{
return new Employee();//Employee is of type IEmployee
}
}

It compiless fine. But when referencing it in a Windows Form I get Error:
"Cannot serialize interface EmployeeCommon. IEmployee.".

The reason I do this is that I want a web service to return objects that
inherits an interface, so I can cast that object to an interface and use it
in the windows. I do this because I want it to be in synch with the Windows
implementation that is using IEmployee as well. So when I cast it, both of
the objects are of type IEmployee.

Is there a way to do this, please?
--
Regards,

Mike
Dec 1 '05 #1
1 4871
Does anyone have an answer for this? I am having the same problem.

"Mike9900" wrote:
I would like to return an object which inherits an interface. A web service
instantiate a class that inherits that interface and returns that object. But
I get error when referencing the web service from windows form. the error is:
"System.NotSupp ortedException: Cannot serialize interface
EmployeeCommon. IEmployee."

EmployeeCommon. IEmployee is an interface which is inerited by the
instantiated class. That class is instantiated and returned by the web
service called CompanySystem using a method called CreateEmployeeS ystem()
that returns IEmployee . IEmployee is inherited by the class Employee.

Here are the codes for what I am doing:

/*INTERFACE: this code is done in a common.dll project*/
public interface IEmployee
{
String GetName();
Int32 GetID();
}

/////There Codes are done in a web service project
/*CLASS EMPLOYEE TO INHERIT IEMPLOYEE*/
//I have removed System.Web.Serv ices.WebService
public class Employee :IEmployee
{
public Employee()
{}
....implements all the interface methods
}
public class CompanySystem : System.Web.Serv ices.WebService
{
public CompanySystem()
{}
[WebMethod] //return I employee
public IEmployee CreateEmployeeS ystem()
{
return new Employee();//Employee is of type IEmployee
}
}

It compiless fine. But when referencing it in a Windows Form I get Error:
"Cannot serialize interface EmployeeCommon. IEmployee.".

The reason I do this is that I want a web service to return objects that
inherits an interface, so I can cast that object to an interface and use it
in the windows. I do this because I want it to be in synch with the Windows
implementation that is using IEmployee as well. So when I cast it, both of
the objects are of type IEmployee.

Is there a way to do this, please?
--
Regards,

Mike

Jan 26 '06 #2

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

Similar topics

1
1365
by: greg | last post by:
Hi I use a COM object to interface with domain search from SRS and it returns: SRSPLUSLib.SrsClass srs = new SRSPLUSLib.SrsClass(); srs.Startup(); SRSPLUSLib.IDictionary dic = srs.DomainInfo(domain,tld);
0
930
by: greg | last post by:
How do I get this interface in plain file - I mean I added reference but dont see no file generated Here is my orig. message Hi I use a COM object to interface with domain search from SRS and it returns:
3
1907
by: thomson | last post by:
Hi all, Can any one tell me what happens when an object is casted to an interface, somthing bit deeper, the case is i do have an interface Ifunction which has got one method display(), and i have implemented the interface in one class and i have implemented the display function in the class, So when i say ((Ifunction)object).display(), it calls the function
0
1203
by: suresh_C# | last post by:
Also any link/doc which has sample code for returning custom class object from Web Service?
15
26257
by: mr.peteryu | last post by:
Hi, Can someone explain the idea behind casting to an interface? For example: -> I have an IInterface that contains a Read() method. -> I have an object "obj" that implements IInterface. Why would someone do the following and what does it mean?
2
1626
by: Asim Qazi | last post by:
Hi All public class MyResponse { public bool m_bStatus; public string m_szErrorCode; public string m_szMessage; }
1
1422
by: Vanecelli | last post by:
So, with the luck on the first dilemna I thought I'd ask here again. I have an array that's returning instead of what it's assigned. I am creating an array to hold a listbox list. function list(name, value) { this.name = name; this.value = value; } function populateList(b){
0
1354
ntxsoft
by: ntxsoft | last post by:
Hello everybody, I have a small problem while returning array from web service. Firstly I'm new at java web services and I'm using netbeans 6 with glassfish 2. The problem is I have a class, name is "Experience" and I want to return Experience array from service. In web service I implement like that @WebMethod(operationName = "getExperience") public Experience getExperience( @WebParam(name = "user") User user, ...
3
1831
by: Ron | last post by:
I have a situation where I need to test if a Control implements from a specific Interface to avoid an invalid cast exception: foreach (Control ctrl in this.Controls) { // Need to test to see if ctrl inherits interface ICustomControl here ICustomControl control = (ICustomControl)ctrl; } Thanks!
0
8087
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
8025
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8509
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
8493
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
8365
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5499
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
3993
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...
0
4053
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.