RE: Webservices, Interfaces and Polymorphism in proxy classes.
- From: Daniel P. <DanielP@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 20 Oct 2006 13:00:01 -0700
I solved the type sharing between the web services tier and the client app by
writing some code that takes the object and turns it into the target object.
Basically you have two identical types and using reflaction you create the
target type from the source type. I did not publish the code yet but I'm
thinking to do it in the near future:
http://danutp.blogspot.com/2006/06/web-services-sharing-data-between.html
"David Jessee" wrote:
I've run into this myself. And yes...I've jumped through hoops to get it to.
work.
With web services, the only interface you REALLY have is the WSDL contract
from the client to the server. In reality the server could be in Java, or
some other language so, by the nature of how web services work, you really
shouldn't be using a .NET interface to enforce the design pattern because you
don't know what the server technology is. This is why, when you set the
reference in Studio, it creates the client class as well as all types that
need to be used. If you're trying to use the same library on the client and
server (e.g. a customer object returned from a web method) you end up with 2
customer types....the type you defined and the type that was generated when
the reference was set via the wsdl tool.
But, I'm with you, I want an interface, mostly because if I'm programming
against interfaces, I can enforce the contract at the code level and also
create proxy server classes for testing purposes.
So, what's the solution??
There isn't really a good one. In most of these cases, I ended up using
Remoting instead and then creating web services that are used by client that
I do not have control over. Web services don't really have that much to do
with OOP, so if you try to take a strict OOP approach, you're going to get a
couple bumps in the road.
The only solution I've been able to come up with is:
1) execute the wsdl.exe tool manually, supplying parameters that tell the
runtime which .NET types map to the different SOAP types. This allows you to
use the same library on the client and the server.
2) Create a Wrapper Class that implements the appropriate interface. The
wrapper class would simply delegate the calls to the generated client class
generated by the WSDL tool. This way, your code sees the wrapper, which
defines Interface X
Hairy, I know....
"JupiterMoonBeam" wrote:
Hello,
I wonder if anyone can help.
As a rule I have a design policy of programming to interfaces
especially with 'data' classes. I like a client to be responsible for
implementing its own version of classes it sends to a service rather
than the service dictating what the class should be. This provides
immense flexibility and is a good practice. For example in a web
application if I need to submit a login I have a service with the
method:
public bool Logon(ILogonCredentials);
And then on the web page I can do:
public class MyPage: ILogonCredentials
{
public string ILogonCredentials.UserName
{
get { return UserNameTextBox.Text; }
}
public string ILogonCredentials.Password
{
get { return PasswordTextBox.Text; }
}
public void LogonOnClick(...)
{
LogonService.Logon(this);
}
}
There are also other reasons for doing this as I can implement
different class logic in web apps over desktop apps etc.
The problem I am having is trying to establish how to do this with web
services. I understand that the web service itself MUST implement a
real class to desirialize the request to but when I add a web reference
in VisualStudio 2005 I want to be given interfaces for the objects that
are serialized/deserialized between the service and client (though not
for the service itself) so I can be free to use the benefits of
polymorphism and have multiple implementations of the interfaces
through my clients.
I know it's completely technically possible to do as I have do it
easily by editing the auto generated code but this is a BAD thing (as
VS will just nuke it at will) and I don't want to be having to manually
write my proxy's with all the events and yuk yuk yuk.
Any help would be GREATLY appreciated: I wan't to use some OOP
techniques in a OOP language and I know it must be possible I just need
the secret key.
Many thanks in advance.
- Follow-Ups:
- Re: Webservices, Interfaces and Polymorphism in proxy classes.
- From: JupiterMoonBeam
- Re: Webservices, Interfaces and Polymorphism in proxy classes.
- References:
- Webservices, Interfaces and Polymorphism in proxy classes.
- From: JupiterMoonBeam
- RE: Webservices, Interfaces and Polymorphism in proxy classes.
- From: David Jessee
- Webservices, Interfaces and Polymorphism in proxy classes.
- Prev by Date: RE: Webservices, Interfaces and Polymorphism in proxy classes.
- Next by Date: Strategies for Web Service to Unmanaged DLL
- Previous by thread: RE: Webservices, Interfaces and Polymorphism in proxy classes.
- Next by thread: Re: Webservices, Interfaces and Polymorphism in proxy classes.
- Index(es):
Relevant Pages
|