Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Implementing custom interfaces

Reply
Thread Tools

Implementing custom interfaces

 
 
Hari
Guest
Posts: n/a
 
      03-03-2006
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
 
Reply With Quote
 
 
 
 
FoxtrotEcho
Guest
Posts: n/a
 
      03-07-2006
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

 
Reply With Quote
 
 
 
 
Hari
Guest
Posts: n/a
 
      03-07-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
extending classes and implementing interfaces C++ style interec@interec.net C++ 13 02-02-2007 06:11 PM
Declaring and implementing exceptions inside interfaces? josh Java 6 12-19-2006 08:29 AM
Is there a way to declare a reference as being a type implementing multiple interfaces? Oliver Wong Java 16 06-28-2006 05:22 PM
Implementing Legacy Byte Packed Message Interfaces Chris Java 6 11-07-2004 09:54 AM
Implementing "package" interfaces James D Carroll Java 4 06-28-2004 02:59 PM



Advertisments