Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / August 2007

Tip: Looking for answers? Try searching our database.

Need some help reading instructions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gustaf - 07 Aug 2007 16:05 GMT
I found what appears to be the solution to my problem in this old thread:

 http://groups.google.se/group/microsoft.public.dotnet.framework.aspnet.webservic
es/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
John Saunders [MVP] - 08 Aug 2007 01:27 GMT
>I found what appears to be the solution to my problem in this old thread:
>
[quoted text clipped - 14 lines]
> 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.
Signature

John Saunders [MVP]

Gustaf - 08 Aug 2007 10:32 GMT
> 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]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.