Inheritence and Web Services

J

Jeff Cooper

Hi Folks,

Sorry, this is kinda long, but I couldn't find an answer anywhere... Any
ideas would be appreciated.

I have several web services (several asmx files) in a project. They all are
variations of some basic functionality, but each with different functions.
However, there are a few functions that are common to all.

So, I created a service called myMainService and put the common functions
into it:

<System.Web.Services.WebService(Namespace:="http://tempuri.org/VHFDBQS/myMai
nService")> _
Public Class myMainService
Inherits System.Web.Services.WebService
... functions here ...
End Class

Now, I create another webservice and declare is as follows:

<System.Web.Services.WebService(Namespace :=
"http://tempuri.org/VHFDBQS/myDerivedService")> _
Public Class myDerivedService
Inherits myMainService
... some functions specific to this class ...
End Class

.... more services are also created, each in its own asmx file ---
myOtherDerivedService, YetAnotherDerivedService, etc, all with "Inherits
myMainService"...

In my aspnet application, I would like to pass a reference to any of the the
derived classes to a function. I have a function in the app that accepts a
paramter of myMainService.myMainService:

Private Function SetupMyService(ByVal Svc As myMainService.myMainService)
Svc.Credentials = Net.CredentialCache.DefaultCredentials
If Svc.CookieContainer Is Nothing Then
Svc.CookieContainer = New System.Net.CookieContainer
End If
'SetConnectionString is a function in the base class myMainService
Svc.SetConnectionString(HttpContext.Current.Session("ConnectionString"))
End Function

Since I'm declaring this function as accepting myMainService, my aspnet
project has a web reference to myMainService along with web references to
each of the derived services. This way, the function knows what
myMainService is.

My thinking is, I can set the object passed in Svc = myDerivedService or
myOtherDerivedService or whatever. Example

Dim Obj as new myDerivedService.myDerivedService
SetupMyService(Obj)

I also tried this:

Dim Obj as myMainService.myMainService = myDerivedService.myDerivedService
SetupMyService(Obj)

Neither works. I'm told: "Value of type
'ServicesProject.myDerivedService.myDerivedServicecannot be converted to
'ServicesProject.myMainService.myMainService."

Why would this be? If I create a regular class in an application, derive
another class from it, I can pass an object referencing the derived class to
a function declared to accept the baseclass. Why can't the same be done with
Web Services?

Is there some strange rule about inheriting from other web services and can
anyone suggest a fix or workaround?

Thanks,

Jeff
 

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,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top