> 2. If the service assembly shall be added to the client assembly, exactly
> what shall be added? There's no DLL in the web service project folders to
> add. Is it possible to generate one?
> Please ignore Mr. Rogers' suggestion. It produces unmaintainable code.
> Consider that most developers expect generated code (the proxy) to be
> able to be regenerated with no ill-effects. Mr. Rogers would have you
> edit the generated proxy file, in the hopes that nobody will ever do an
> "Update Web Reference" command and wipe out your changes.
Thank you John. I see no other way than editing the generated code, since it doesn't come out right. After working on this for the past few weeks, I've started to look upon the Add Web Reference wizard (or wsdl.exe) as a tool that does half the job -- and then you have to add to and tweak the code to your liking, and make sure you never use "Update Web Reference".
Like the original poster in the old thread, I need to return a collection class from the web service, but when I create a client and add a web reference to it, the service returns an object array rather than a collection class. Rogers says "This is the default behavior of the proxy generator". I'd say it's a bug. The classes on the client are supposed to *mirror* those on the web service. Instead, the proxy generator removes the collection class and replace its occurence in the web method with an object array, so that
[WebMethod]
public UserList GetUserList()
becomes
[WebMethod]
public User[] GetUserList()
The steps to make this right again is to add a UserList class to the generated classes, and then modify how GetUserList() is defined. The first is simple, but the second is not.
> Also, this suggestion totally violates the encapsulation of the server,
> since now the client is dependent on implementation specifics of the
> service. Those specifics (extra methods on types, for instance), are now
> part of the contract, even though they cannot be described by WSDL.
If it helps the Add Web Reference wizard to produce correct code, I've no problem with it. As I understand Rogers, the reference wouldn't be needed after the proxy class has been created.
> Mr. Rogers was no doubt assuming that you use an ASP.NET Web Service
> Project, not a Web Service Web Site (or whatever it's called). Those
> produce an assembly.
I'll look more into the ASP.NET Web Service Application project type.
Gustaf
John Saunders [MVP] - 08 Aug 2007 17:24 GMT
>> Please ignore Mr. Rogers' suggestion. It produces unmaintainable code.
>> Consider that most developers expect generated code (the proxy) to be
[quoted text clipped - 16 lines]
> the collection class and replace its occurence in the web method with an
> object array, so that
The proxy classes are NOT meant to mirror those of the service. This is a
fundamental misunderstanding of the Web Services platform. Here's how it
works in .NET:
When you use Add Web Reference, a query is sent to the server with "?WSDL"
tacked on to the end of it. This causes ASP.NET to create a WSDL and return
it to the client (which in this case is Visual Studio). VS uses the WSDL to
create proxy classes.
WSDL depends on XML Schema to describe the types used to communicate to and
from the web service. XML Schema has no concept of a collection. It only has
the concept of repeated elements. Therefore, the generated proxy will use an
array instead of a collection.
The Web Services platform is meant to be cross-platform. As such, it depends
on industry standards like WSDL and XSD. The consequence of this is that
you're stuck with sort of a least-common-denominator situation - you can't
have collections because some platforms don't have collections. The same
goes for all the other things you can't have, like properties, indexers,
iterators, methods on non-WebService types, etc.
There is nothing wrong with _adding_ to the generated proxy class. You can
either derive from it, or else you can add to it through partial classes. If
you want a nice, convenient, collection-based interface to the web service,
then you are free to define one on top of the implementation generated by
Visual Studio. But you should NEVER edit generated code!
> [WebMethod]
> public UserList GetUserList()
[quoted text clipped - 16 lines]
> problem with it. As I understand Rogers, the reference wouldn't be needed
> after the proxy class has been created.
This is not the case.
>> Mr. Rogers was no doubt assuming that you use an ASP.NET Web Service
>> Project, not a Web Service Web Site (or whatever it's called). Those
>> produce an assembly.
>
> I'll look more into the ASP.NET Web Service Application project type.
You should. "Web Sites" are not even a project type. They are useful for
what they're called - web sites, not for web applications.

Signature
John Saunders [MVP]