Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2005

Tip: Looking for answers? Try searching our database.

Using Interface in a Webservice client

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike9900 - 30 Nov 2005 06:06 GMT
I want to use an interface in both the webservice and its client. For
example, the web service implements an interface and then the client cast
that webservice to the inteface. It seems impossible, but I am wondering if
there is a way.

The code below shows how I want it:

/*INTERFACE*/
  public interface IEmployee
   {
       String GetName();
       Int32 GetID();

   }

/* WEBSERVICE*/
public class Employee : System.Web.Services.WebService,IEmployee
{
   public Employee()
   {

       //Uncomment the following line if using designed components
       //InitializeComponent();
   }
   [WebMethod]
   public string GetName()
   {
       return "Ali";
   }
   [WebMethod]
   public Int32 GetID()
   {
       return 2333;
   }
}

/*Windows Client*/
//but this code is not casting, return null
public IEmployee GetEmployee()
{
//WSEmployee is the webservice reference
return  new WSEmployee.Employee() as IEmployee;
}

Signature

Mike

DC - 30 Nov 2005 21:54 GMT
The cast in the client-side code does not work probably because the
webservice proxy does not actually implement  IEmployee.

your code like this:

> public IEmployee GetEmployee()
> {
> //WSEmployee is the webservice reference
> return  new WSEmployee.Employee() as IEmployee;
> }

...I am guessing WSEmployee.Employee is the client-side proxy class
generated by wsdl.exe ?    Open the .cs file and examine it and you'll see
that you have something like this:

public class Employee : System.Web.Services.Protocols.SoapHttpClientProtocol
{
 public String GetName(...) {...}
 public Int32 GetId(...)  {...}
}

you must modify the generated (client-side) class to specifically state that
it implements your IEmployee interface. like so:

public class Employee :
System.Web.Services.Protocols.SoapHttpClientProtocol, IEmployee {
....
}

Then compile your client and it should work.

-D

>I want to use an interface in both the webservice and its client. For
> example, the web service implements an interface and then the client cast
[quoted text clipped - 40 lines]
> return  new WSEmployee.Employee() as IEmployee;
> }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.