Webservice inheriting from interface

Discussion in 'ASP .Net Web Services' started by Lopamudra, Mar 14, 2007.

  1. Lopamudra

    Lopamudra Guest

    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
     
    Lopamudra, Mar 14, 2007
    #1
    1. Advertising

  2. "Lopamudra" <> wrote in message
    news:...
    > 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
     
    John Saunders, Mar 14, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wildepiet
    Replies:
    0
    Views:
    1,864
    Wildepiet
    Jun 14, 2004
  2. cyberco
    Replies:
    8
    Views:
    492
    cyberco
    Feb 25, 2006
  3. Replies:
    1
    Views:
    316
    Rolf Magnus
    Apr 6, 2006
  4. Xah Lee
    Replies:
    15
    Views:
    586
    Sherm Pendley
    Mar 23, 2007
  5. Xah Lee
    Replies:
    15
    Views:
    632
    Sherm Pendley
    Mar 23, 2007
Loading...

Share This Page