Webservice inheriting from interface

L

Lopamudra

Hi,

I have a webservice which inherits additionally from an interface. This
webservice provides implementation for the methods in the interface as well
as provides addtiional methods.

One of the methods of my assembly takes as parameter a type of the
interface. My webservice instance should be passed as the value for this
parameter. However, I am getting an Invalid Cast Exception.

I have posted the code below:

MyWebservice.asmx:

using myInterfaceAssembly; //Contains the interface

public class MyWebservice : System.Web.Services.WebService, myInterface {

public MyWebservice()
{ }

[WebMethod]
public string getUserName(string userID) {
return ("xxx"); //Simplified the code for posting in forum
}

}

myWebform.aspx:

MyMethod signature:
MyMethod(System.Web.UI.Page ,
myInterfaceAssembly.myInterface);

MyMethod call:
MyMethod(this, new MyWebservice()); //Call to my method,
passing webservice instance

This cast is cuasing issue. Any inputs?

Regards
Lopa
 
J

John Saunders

Lopamudra said:
Hi,

I have a webservice which inherits additionally from an interface. This
webservice provides implementation for the methods in the interface as
well
as provides addtiional methods.

One of the methods of my assembly takes as parameter a type of the
interface. My webservice instance should be passed as the value for this
parameter. However, I am getting an Invalid Cast Exception.

I have posted the code below:

MyWebservice.asmx:

using myInterfaceAssembly; //Contains the interface

public class MyWebservice : System.Web.Services.WebService, myInterface {

public MyWebservice()
{ }

[WebMethod]
public string getUserName(string userID) {
return ("xxx"); //Simplified the code for posting in forum
}

}

myWebform.aspx:

MyMethod signature:
MyMethod(System.Web.UI.Page ,
myInterfaceAssembly.myInterface);

MyMethod call:
MyMethod(this, new MyWebservice()); //Call to my method,
passing webservice instance

This cast is cuasing issue. Any inputs?

I'm really not sure what you're doing here. Are the web site and the web
service on the same machine? Are they in the same application?

If not, then perhaps the web site has a Web Reference to the web service? If
so, take a look at the Reference.cs file under the Web Reference (you need
to do Show All Files in order to see it). Look at the definition of the
proxy class for the web service, and I bet you'll find that it does not show
your interface.

Interfaces are one of the many platform-specific features that don't
translate into web services. If this is what you're trying to do, then you
need another way of doing it.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top