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

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.NotSupportedException: 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 CreateEmployeeSystem()
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.Services.WebService
public class Employee :IEmployee
{
public Employee()
{}
.....implements all the interface methods
}
public class CompanySystem : System.Web.Services.WebService
{
public CompanySystem()
{}
[WebMethod] //return I employee
public IEmployee CreateEmployeeSystem()
{
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 4853
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.NotSupportedException: 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 CreateEmployeeSystem()
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.Services.WebService
public class Employee :IEmployee
{
public Employee()
{}
....implements all the interface methods
}
public class CompanySystem : System.Web.Services.WebService
{
public CompanySystem()
{}
[WebMethod] //return I employee
public IEmployee CreateEmployeeSystem()
{
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
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 =...
0
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...
3
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...
0
by: suresh_C# | last post by:
Also any link/doc which has sample code for returning custom class object from Web Service?
15
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. ...
2
by: Asim Qazi | last post by:
Hi All public class MyResponse { public bool m_bStatus; public string m_szErrorCode; public string m_szMessage; }
1
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...
0
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...
3
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...
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
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.