473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

BUG: Web Services & Polymorphism

This is a definite and reproduceable bug in Web Services, Visual Studio 2003.

Here is a simple example. Create a web service...

// this represents an original version of an object
class ObjectV1 { ... } // holds some arbitrary data

// this represents a newer version with extra information
class ObjectV2 : ObjectV1 { ... } // adds some additional information

// this is an 'original' function, which returns the base class original
information
[WebMethod]
public ObjectV1 _GetObject()
{
// this represents the base layer was updated with a new derived
// object with extended information.
return new ObjectV2();
}

// this is a stub function to return the new version explicitly
[WebMethod]
public ObjectV2 _GetObject2()
{
// very simple upcast knowing the base layer is updated
// no need to reimplement everything redundantly for this new type
return _GetObject() as ObjectV2;
}

Create a web service client... Everything WORKS...

But now... following the same extensibility model...

Extend the web service to return ObjectV3...

class ObjectV3 : ObjectV2 { ... } // latest extended version

// this represents the base layer is returning the latest object version
// through the otherwise non-changing public layer
[WebMethod]
public ObjectV1 _GetObject()
{
return new ObjectV3();
}

Now, at this point, the client is still using _GetObject operating on
ObjectV1.

WITHOUT REGENERATING THE WEB SERVICE ON THE CLIENT SIDE...

The client crashes with an error parsing the XML response. Why? ObjectV3 is
polymorphically compatible with ObjectV2. The call signature of _GetObject
hasn't changed. It is still legal usage of polymorphism. There wasn't a
problem with it when it was V2->V1.

You will actually see the problem simply going from V1 to V2, provided you
do not regenerate the WSDL on the client side.

Why not regenerate the client's web service definition?
This represents extending a web service while still supporting previous
versions of the web service clients, who retrieve a polymorphic downcast of a
derived type, i.e. operate on an inherited type from its base class. They are
installed, and need to continue functioning.

Why can't the XML be parsed without regenerating the web client's web
service definition?

You're wrong if you think it SHOULD be this way. Also, don't suggest using
an alternate extensibility model. This model was not my idea, but in itself,
it is very reasonable, and it is probably very common. I already know how to
resolve it by rearchitecturing the web service to promote extensibility...
Boxing and unboxing the parameters and return object with version control.

I am basically looking for a resolution that doesn't require redundant
reimplementation and maintanence of several versions of code.
Oct 19 '05 #1
3 2115
It is still a BUG, but here is an acceptable solution...

You will have to implement copy constructors on all the objects, and change
the _GetObject function to:

return new ObjectV1( base layer's return object );

The copy constructor will ensure that strictly ObjectV1 is returned, and
this essentially disables polymorphism over the web service chasm.

You still need things like _GetObjectV2, _GetObjectV3, simply for the reason
that the web service definition will not recognize ObjectV2, ObjectV3 unless
one of the web service functions returns it.

Also, the caller will need to call the appropriate V2, V3, whereas with the
PROPER way, you would have 1 function, and the caller could recognize the
object type polymorphically. Because of the BUG, the PROPER ways are not
possible.
Oct 19 '05 #2
Marshal wrote:
This is a definite and reproduceable bug in Web Services, Visual
Studio 2003.

Here is a simple example. Create a web service...

// this represents an original version of an object
class ObjectV1 { ... } // holds some arbitrary data

// this represents a newer version with extra information
class ObjectV2 : ObjectV1 { ... } // adds some additional
information

// this is an 'original' function, which returns the base class
original information
[WebMethod]
public ObjectV1 _GetObject()
{
// this represents the base layer was updated with a new derived
// object with extended information.
return new ObjectV2();
}

// this is a stub function to return the new version explicitly
[WebMethod]
public ObjectV2 _GetObject2()
{
// very simple upcast knowing the base layer is updated
// no need to reimplement everything redundantly for this new type
return _GetObject() as ObjectV2;
}

Create a web service client... Everything WORKS...

But now... following the same extensibility model...

Extend the web service to return ObjectV3...

class ObjectV3 : ObjectV2 { ... } // latest extended version

// this represents the base layer is returning the latest object
version // through the otherwise non-changing public layer
[WebMethod]
public ObjectV1 _GetObject()
{
return new ObjectV3();
}

Now, at this point, the client is still using _GetObject operating on
ObjectV1.

WITHOUT REGENERATING THE WEB SERVICE ON THE CLIENT SIDE...

The client crashes with an error parsing the XML response. Why?
ObjectV3 is polymorphically compatible with ObjectV2. The call
signature of _GetObject hasn't changed. It is still legal usage of
polymorphism. There wasn't a problem with it when it was V2->V1.

You will actually see the problem simply going from V1 to V2,
provided you do not regenerate the WSDL on the client side.

Why not regenerate the client's web service definition?
This represents extending a web service while still supporting
previous versions of the web service clients, who retrieve a
polymorphic downcast of a derived type, i.e. operate on an inherited
type from its base class. They are installed, and need to continue
functioning.

Why can't the XML be parsed without regenerating the web client's web
service definition?

You're wrong if you think it SHOULD be this way. Also, don't suggest
using an alternate extensibility model. This model was not my idea,
but in itself, it is very reasonable, and it is probably very common.
I already know how to resolve it by rearchitecturing the web service
to promote extensibility... Boxing and unboxing the parameters and
return object with version control.

I am basically looking for a resolution that doesn't require
redundant reimplementation and maintanence of several versions of
code.


this is caused by the fact that the client has a proxy class for the
service, which in fact contains NEW classes for the same types. Because
it gets a type B from a given method M, wsdl.exe simply generates a
class of type B, it doesn't know if B derives from A or not.

In .NET 2.0, this is changed, there you can specify a SchemaImporter
class which tells the wsdl tool to generate proxy classes with the
known types and not generate new types.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Oct 20 '05 #3
Bug... perhaps. You are not exactly using the normal mechanisms for
extending a web service. The framework never promised the behavior you are
expecting, so it would be difficult to say that that the test team should
have found this. I'd like to be proven wrong. If you can find somewhere in
the spec for a web service that it says that using derivation, rather than
XML Versioning, for incremental versioning, would be a supported technique,
then I'm happy to eat my words.

You found a technique and jumped to conclusions about what it did for you
and what it could be useful for, without testing your conclusions. A
reasonable part of the responsibility for this situation rests squarely on
your shoulders.

Caveat: I am not a member of the product team or the support team. I have
not seen your situation before. I spend a fair amount of time on these
boards, and I do not know of any other users of VS who attempted to perform
versioning through subclassing. If you want to call customer support, I
encourage you to do so. They have access to a rather large knowledge base
that may have some more detail than I have access to.

My suggestion: change the code so that the original call returns an object
of the original type. The second call returns an object of the second type
and the third call returns an object of the third type. Newest client code
would use the newest call specifically. The underlying logic can all take
place using the newest object, and the oldest service will convert the
results back to the oldest return type.

Good luck
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Marshal" <Ma*****@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
This is a definite and reproduceable bug in Web Services, Visual Studio
2003.

Here is a simple example. Create a web service...

// this represents an original version of an object
class ObjectV1 { ... } // holds some arbitrary data

// this represents a newer version with extra information
class ObjectV2 : ObjectV1 { ... } // adds some additional information

// this is an 'original' function, which returns the base class original
information
[WebMethod]
public ObjectV1 _GetObject()
{
// this represents the base layer was updated with a new derived
// object with extended information.
return new ObjectV2();
}

// this is a stub function to return the new version explicitly
[WebMethod]
public ObjectV2 _GetObject2()
{
// very simple upcast knowing the base layer is updated
// no need to reimplement everything redundantly for this new type
return _GetObject() as ObjectV2;
}

Create a web service client... Everything WORKS...

But now... following the same extensibility model...

Extend the web service to return ObjectV3...

class ObjectV3 : ObjectV2 { ... } // latest extended version

// this represents the base layer is returning the latest object version
// through the otherwise non-changing public layer
[WebMethod]
public ObjectV1 _GetObject()
{
return new ObjectV3();
}

Now, at this point, the client is still using _GetObject operating on
ObjectV1.

WITHOUT REGENERATING THE WEB SERVICE ON THE CLIENT SIDE...

The client crashes with an error parsing the XML response. Why? ObjectV3
is
polymorphically compatible with ObjectV2. The call signature of _GetObject
hasn't changed. It is still legal usage of polymorphism. There wasn't a
problem with it when it was V2->V1.

You will actually see the problem simply going from V1 to V2, provided you
do not regenerate the WSDL on the client side.

Why not regenerate the client's web service definition?
This represents extending a web service while still supporting previous
versions of the web service clients, who retrieve a polymorphic downcast
of a
derived type, i.e. operate on an inherited type from its base class. They
are
installed, and need to continue functioning.

Why can't the XML be parsed without regenerating the web client's web
service definition?

You're wrong if you think it SHOULD be this way. Also, don't suggest using
an alternate extensibility model. This model was not my idea, but in
itself,
it is very reasonable, and it is probably very common. I already know how
to
resolve it by rearchitecturing the web service to promote extensibility...
Boxing and unboxing the parameters and return object with version control.

I am basically looking for a resolution that doesn't require redundant
reimplementation and maintanence of several versions of code.

Oct 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stuart D. Gathman | last post by:
Running the following with Python 2.2.2: from email.Parser import Parser txt = """Subject: IE is Evil Content-Type: image/pjpeg; name="Jim&amp;&amp;Jill" <html> </html> """
4
by: The Directive | last post by:
I can't understand why in this folling example the message "Base.Draw()" is printed. Shouldn't "Derive.Draw" be printed because of polymorphism? How can I rewrite this example using a vector to...
6
by: Mårten Herberthson | last post by:
Introduction: As we all know, values of any class may be assigned to a reference of a superclass. This is simple polymorphism. So if you have a class A and a class B that inherits from A you can...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
5
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
15
by: rwf_20 | last post by:
I just wanted to throw this up here in case anyone smarter than me has a suggestion/workaround: Problem: I have a classic producer/consumer system which accepts 'commands' from a socket and...
2
by: Marshal | last post by:
This is a definite and reproduceable bug in Web Services, Visual Studio 2003. Here is a simple example. Create a web service... // this represents an original version of an object class...
27
by: Chad | last post by:
The problem is: Write a recursive version of the function reverse(s), which reverses the string s in place. In "The C Answer Book", Second Edition, near the bottom of page 95, the authors say...
9
by: Royt | last post by:
Maybe it's a stupid question, but I really couldn't figure it out. C++ is expected to be a better C, provides compatibility with C, and is able to do all that C can do. however, the number of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.