Need some help reading instructions

G

Gustaf

I found what appears to be the solution to my problem in this old thread:

http://groups.google.se/group/micro...ervices/browse_thread/thread/147cb18619cc937/

Dan Rogers of Microsoft writes:

[...] share the assembly that you use on the client and on
the server, and change the generated proxy method to return a UserList
class. If you're starting with the generated proxy code, you'll have to
comment out the generated type information, and then add an imports or
using statement, as well as an assembly reference to your project. This
allows the proxy to see the types defined in your assembly, and then
serialize properly to the more advanced userlist type.

I got a number of questions here, but let's start with these two:

1. Shall the service assembly be added to the client assembly, or vice versa, or both?

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?

Gustaf
 
J

John Saunders [MVP]

Gustaf said:
I found what appears to be the solution to my problem in this old thread:


http://groups.google.se/group/micro...ervices/browse_thread/thread/147cb18619cc937/

Dan Rogers of Microsoft writes:

[...] share the assembly that you use on the client and on
the server, and change the generated proxy method to return a UserList
class. If you're starting with the generated proxy code, you'll have to
comment out the generated type information, and then add an imports or
using statement, as well as an assembly reference to your project. This
allows the proxy to see the types defined in your assembly, and then
serialize properly to the more advanced userlist type.

I got a number of questions here, but let's start with these two:

1. Shall the service assembly be added to the client assembly, or vice
versa, or both?

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.

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.
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?

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.

They produce an assembly which is meant to remain on the server and to never
be seen by the client.

If you really need more intimacy between the client and the server, then you
should be using Remoting or WCF, not Web Services.
 
G

Gustaf

John said:
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
 
J

John Saunders [MVP]

Gustaf said:
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

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()

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.

This is not the case.
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top