Re: Need some help reading instructions

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Gustaf" <gustafl@xxxxxxxxxx> wrote in message news:OPI%23$8Z2HHA.5772@xxxxxxxxxxxxxxxxxxxxxxx
John Saunders [MVP] wrote:

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

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.

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.
--
John Saunders [MVP]

.



Relevant Pages

  • Re: Passing User Define class to web service.
    ... First, you should try to update your web reference, then go to the generated ... that when the new web service proxy is ... >> likely problem is that myClass is multiply defined in separate namespaces ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: web service
    ... Can you send a screenshot of the "Add Web Reference" dialog box after you ... I have just tried that web service you specified, and got the WSDL displayed ... ok and was able to generate a proxy class in C# just fine. ...
    (microsoft.public.cert.exam.mcad)
  • Query on typing SoapService methods : Prev: Confused WS, SOA
    ... SoapReceiver, does now allow me to query Myservice.ashx?wsdl to return ... on another machine to create some proxy code classes. ... my wsdl on my initial attempts so far seems to have generated ... Which in the (VS Add Web Reference) proxy generated becomes ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Web Service methods require custom types, VS.NET generated Types are empty
    ... just delete the divNumber_t class definition from the auto-generated proxy ... other folks to fix the WSDL for their Web Service. ... reference in VS.NET 2003 and it generates the proxy code, ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: C# Web Services - usage by non .net clients?
    ... the only thing you need is the WSDL. ... your web service must conform to the WS-I BSP profile if others ... what if I develop a client in delphi or progress or Java? ... Would it be a client specific format of the Proxy class? ...
    (microsoft.public.dotnet.framework.webservices)