RE: Implementing custom interfaces



Hi,

Thanks for the reply.

That gave us some work around over the problem

Regards
Hari

"FoxtrotEcho" wrote:

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
    ... When you added a web reference to your project, ... 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: Custom interfaces
    ... "Robert Scheer" schreef in bericht ... > My web service class implements a custom interface. ... my custom interface is not there. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Custom interfaces
    ... "Robert Scheer" schreef in bericht ... > Public Interface IWebTest ... >>> My web service class implements a custom interface. ... my custom interface is not there. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Update Web Reference - at run time
    ... If the interface designer "breaks" ... If the breakage is in the programming ... When the creator of your web service adds function, ... because new clients might not work with old servers. ...
    (microsoft.public.dotnet.xml)
  • Re: Returning interfaces from web-services and remoting servers?
    ... You could certainly make it appear like the web service and remoting server ... use the same, well-defined interface. ... you've defined an IDocument interface for. ...
    (microsoft.public.dotnet.framework)