Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET WebService
Hi Everyone,
 
How can I inherit an abstract class written in a web service class by a class within a project that referenced that web service?
 
EG:
 
Web Service Class
[WebService(Namespace = "...")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class AppService : System.Web.Services.WebService
{
    public abstract class InheritMe<T>
    {
        ...
    }
}
 

Local Class
class ConcreteClass : WebService.AppService.InheritMe<int>
{
    ...
}
 

Please, I really need help.
Thanks in advance..
Posted 7-Nov-11 21:35pm
Edited 8-Nov-11 14:48pm
v5
Comments
Jephunneh Malazarte at 8-Nov-11 3:41am
   
Interesting question... I don't have the answer for now :)
I am hoping to have an idea why need to inherit the class from webservice.
unknowndentified10111 at 8-Nov-11 3:43am
   
Thanks for the reply. I have a generic data access class that can only be inherited. That's why I need an abstract class, but if it is a concrete class, how can I access it?
Technology Digestified at 8-Nov-11 3:53am
   
But why you need to inherit abstract class from web service? Don't you afford to make the same abstract class in the application where you are using your web service...
unknowndentified10111 at 8-Nov-11 4:01am
   
The abstract generic data access class has methods that connects to the database within the same server as the web service. It can also be done by making the data access class concrete and instantiate it in the local concrete class and create methods for each method of that data access class, I just want to inherit it so that it would be easier, but if there has no other option, how can I access a concrete class written inside a web service class?
Jephunneh Malazarte at 8-Nov-11 4:42am
   
oh so the reason why you need that is to call the method defined in your webservice? is that correct? coz i have a solution if that's the case.
unknowndentified10111 at 8-Nov-11 4:51am
   
Yes, but I need it to be generic because it defines an entity with a data type of T, or a defined data type, and I think changing it to a concrete class is hypothetically impossible(contradicting my comment here a while ago).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

http://forums.asp.net/t/1509177.aspx/1[^]
 
I am sure this will help you.Enjoy
  Permalink  
Comments
unknowndentified10111 at 8-Nov-11 4:46am
   
Thanks for the answer but my question is how to inherit an abstract class from a web service class, not from a class to the web service class, to the class within the project that referenced that web service. Your reply is highly appreciated though.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

What's the problem?

If your abstract class is declared as the following:

namespace MyWebServiceNamespace
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class AppService : System.Web.Services.WebService
    {
        // ...

        public abstract class InheritMe<T>
        {
            // ...
        }
 
        // ...
    }
}

you can inherit it as the following:

public class MyClass : MyWebServiceNamespace.AppService.InheritMe<int>
{
}

Because your class is declared in a WebService you also have to add a reference to System.Web.Services, in the project that contains the class that inherits your abstract class.

  Permalink  
Comments
unknowndentified10111 at 8-Nov-11 20:16pm
   
That would only work if the class that inherit the web service class is in the same project as the web service or it referenced the project of that web service. What I have was the class that needs to inherit the web service class is in a project that web referenced that web service.
Shmuel Zang at 9-Nov-11 10:46am
   
Why do you want to do something like that? What is the problem with declaring the abstract class, in a separate project and, reference this project from the WebService's project and from the other project that inherits the abstract class?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 260
1 Sergey Alexandrovich Kryukov 150
2 ChauhanAjay 120
3 BotCar 105
4 Richard MacCutchan 100
0 Sergey Alexandrovich Kryukov 9,056
1 OriginalGriff 7,981
2 CPallini 2,613
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 8 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100