Re: treating an object as another type (not castable)
- From: "Gael Fraiteur" <gael@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 4 Aug 2005 10:50:57 +0200
I think you are right, proxy classes of web services cause a design problem.
I guess the right design would be to an assembly containing the interface
and the types constituting the service interface. The server would implement
the interface as a web service server and the client would implement it as a
web service proxy.
It is not forbidden to design your application this way, but Microsoft tools
do not support it directly. There is no similar code generation tool for
this.
When you have control over the client and the server, another approach is to
use remoting over SOAP/HTTP hosted in IIS, but it has much less support of
the framework than Web Services (difficult customization, no WSE, ...).
Maybe this issue has been solved with Vista...
--
Gael Fraiteur
http://gael.fraiteur.net
Prague, Czech Republic
----------------------------------------------------------------
PostSharp is an open-source post-compiler for .NET
http://gael.fraiteur.net/postsharp.aspx
----------------------------------------------------------------
"Andy Fish" <ajfish@xxxxxxxxxxxxxxxx> wrote in message
news:eBPNUaEmFHA.1996@xxxxxxxxxxxxxxxxxxxxxxx
> Thanks for the ideas Erick. Unfortunately I don't think any of them is a
> magic bullet.
>
> I would think my problem is quite a common one when using asp.net web
> services. Say you have a web service with a parameter of class A, the
> framework generates a proxy object on the client and a corresponding class
B
> (which actually has the same name as the original class A but is in a
> different namespace). I have no control over the class that it generates
> (e.g. I can't make it implement an interface or anything)
>
> This is fine, but it means that if I have a utility function on the server
> that manipulates objects of class A, it won't work on the client because
the
> object is actually of class B (which is identical to A).
>
> I have the reflection mechanism working now (I don't think it's very
> efficient but I'll find out in time) so it's not vital, but it would be
> interesting to see if there is a better way.
>
> "Erick Sgarbi" <notifications@xxxxxxxxxxxx> wrote in message
> news:O2NwhWDmFHA.3568@xxxxxxxxxxxxxxxxxxxxxxx
> >A couple of ideas:
> >
> > 1. You could use a TypeDelegator to ease your reflection experience by
> > creating a TypeDelegator that would discover MemberInfo from different
> > types with matching member names (and characteristics).
> >
> > 2. Implement matching interfaces on both classes and treat them as the
> > same.
> >
> > 3. Look at some structural patterns
> > (http://www.dofactory.com/Patterns/Patterns.aspx) as you may find
> > something there for bridging your types.
> >
> >
> > I think the last one is the best option however I don't know for sure
how
> > your structures are implemented.
> >
> >
> >> At the moment I'm using reflection to instantiate an object of type B
and
> >> copy all the fields over, but it's a bit fiddly where there are arrays.
> >> is
> >> there an easier way?
> > What is exactly the problem with copying arrays?
> >
> > --
> > Erick Sgarbi
> > www.blog.csharpbox.com
> >
> >
> >
> > "Andy Fish" <ajfish@xxxxxxxxxxxxxxxx> wrote in message
> > news:e2Ug6tCmFHA.1444@xxxxxxxxxxxxxxxxxxxx:
> >
> >> Hi all,
> >>
> >> sorry about the subject but I couldn't think of a sensible way to put
it
> >>
> >> say I have
> >>
> >> class A { public int i; public string s; }
> >> class B { public int i; public string s; }
> >>
> >> now I have an object of type A but I want to treat it as if it were
type
> >> B.
> >> Obviously a cast is not valid.
> >>
> >> I am prepared to guarantee that the declarations of the types are
exactly
> >> the same; the types inherit directly from system.object; have only
public
> >> instance variables of simple types (possibly including arrays); and
have
> >> no
> >> methods or anything else.
> >>
> >> At the moment I'm using reflection to instantiate an object of type B
and
> >> copy all the fields over, but it's a bit fiddly where there are arrays.
> >> is
> >> there an easier way?
> >>
> >> Andy
> >
>
>
.
- Follow-Ups:
- Re: treating an object as another type (not castable)
- From: Andy Fish
- Re: treating an object as another type (not castable)
- References:
- treating an object as another type (not castable)
- From: Andy Fish
- Re: treating an object as another type (not castable)
- From: Erick Sgarbi
- Re: treating an object as another type (not castable)
- From: Andy Fish
- treating an object as another type (not castable)
- Prev by Date: Re: IMetaDataEmit DefineUserString
- Next by Date: MASM problem with long filenames
- Previous by thread: Re: treating an object as another type (not castable)
- Next by thread: Re: treating an object as another type (not castable)
- Index(es):
Relevant Pages
|