RE: Implementing custom interfaces



When you added a web reference to your project, the framework created a class
that derives from SoapHttpClientProtocol (which implements IDisposable). You
can see this yourself if you view all files and naviagte down the web
reference tree until to come to a file named Reference.cs. The class
implemented in this file will not have derived from your interface even if
the methods are clearly there.
If you need that functionality,i.e. to have your class assume the behaviour
of an interface , it is best that create another class in your project and
derive it from the class implemented in Reference.cs and your interface- No
additional code would be required because the class in Reference.cs already
takes care of all implementations.
Now from your console app, instantiate this newly created class instead of
the one created by the framework and extract your interface as required.

ex
public class MyProxy : Service, IMyInterface {
//other customizations here if required.
}

where service is the SoapHttpClientProtocol derived class in Reference.cs
and IMyinterface is your custom interface.

In console app

MyProxy p = new MyProxy();
IMyInterface i = p as IMyInterface;
if (p!=null) //and is should not
{
//use i
}



You could achieve the same result by directly tampering with the framework
generated class, but everytime you update the web reference, you would lose
your customisations.
Hope this helped.



"Hari" wrote:

Hi,

I have created a web service which implements a custom interface.

I have added this web service as a web reference to a console application
that acts as a web service consumer.

After creating an instance for the web service class, when i am trying to
type cast that instance to my custom interface, i am getting
"InvalidTypeCastException" ?

When I do the same for System Interfaces like IDisposable it is working fine.

Can somebody help me with this ?

Thanks in Advance

Regards
Hari
.



Relevant Pages

  • RE: Implementing custom interfaces
    ... that derives from SoapHttpClientProtocol. ... implemented in this file will not have derived from your interface even if ... I have created a web service which implements a custom interface. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Where to start?
    ... You might want to first check if the site offers a web service ... interface. ... If so it might be as easy as "Add web Reference" from the ... >order to work out which flights best suit my needs. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Webservice inheriting from interface
    ... I have a webservice which inherits additionally from an interface. ... then perhaps the web site has a Web Reference to the web service? ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Remoting Objects: style question
    ... Most likely, if you use abstract objects, the first cast will be done in the ... class to which it is cast, regardless of whether it derives from that class. ... acobj will be non-null even though the remoted object is ... > the object actually implements the interface). ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Newbie Modelling Interface Question
    ... > Hardware Interface subsystem. ... > two classes, amongst others, Fram and Rom, which implement the following ... > CrcCheck ... > second is IRWMemory which Fram derives from and provides pv functions Read, ...
    (comp.object)