469,319 Members | 2,446 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Using Interface in a Webservice client

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;
}

--
Mike
Nov 30 '05 #1
1 1947
DC
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.SoapHttpClientProtoc ol
{
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.SoapHttpClientProtoc ol, IEmployee {
.....
}

Then compile your client and it should work.

-D

"Mike9900" <Mi******@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...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;
}

--
Mike

Nov 30 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tim Burris | last post: by
5 posts views Thread by AliR | last post: by
3 posts views Thread by Michael Hoehne | last post: by
2 posts views Thread by Robbert van Geldrop | last post: by
1 post views Thread by Kevin S. Goff | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.