WebService Proxy Classes (using wsdl.exe) ! Need expert help ! MS PEOPLE ?

B

Benne Smith

Hi,

I have three enviroments; a development, a testing and a production
enviroment. I'm making a big application (.exe), which uses alot of
different webservices.

I don't use the webservices by adding a WebReference, since it does not
allow me to keep state (cookiecontainer) or to specify functions on the
classes (like if i want to override the ToString() function on a class from
my webservice). So the only way i can see how i can get this option, is to
generate proxyclasses through wsdl.exe and add the class to my project.

It all works fine, but there's the deal... When I need to switch between a
Development build and a Test build, i've made entries in the Visual Studio
Configuration Manager (which I use with the #if and #endif). It allows me to
take different connectionstrings from the web.config etc.

But since I've generated my Proxy classes through wsdl.exe, it's constructor
has the folllwing line;

this.Url = "http://myserver/mywebservice/myservice.asmx";

This I could wrap with #if and #endif like so;

#if DEV
this.Url = "http://mydevserver/mywebservice/myservice.asmx"; // Notice
myDEVserver
#endif

#if TEST
this.Url = "http://mytestserver/mywebservice/myservice.asmx"; // Notice
myTESTserver
#endif

I also works just fine ! This way i can easily change between enviroments !

B U T (and here's the thing...) when i change a webservice, like
adding/deleting functions, I need to either; 1) edit the proxy class
manually, removing or adding the functions (beginInvoke..., endInvoke...)
corresponding to the changes, OR 2) re-generate the proxy class.

It's easy to see, that if you have a huge project, with loads of webservices
which changes alot, you have to do this alot of times. The problem is, that
when i re-generate the proxy classes, all my functions on the classes in the
proxyclass are overridden, and I have to manually copy them to the clipboard
or something like that, and paste them into the new proxy class, to keep
them.

THIS IS VERY TIME CONSUMING - and frankly drives me crazy !

Dos somebody have a nice solution to this "work process problem" ?

I'm using "Microsoft Development Enviroment 2002" (Microsoft Visual Studio
..NET).

Please help.

Thanks,

Benne
 
T

Trebek

Yeah, I'm in the same boat as you. Same exact problem :(

Something I did to make it easier (although initially just as time
consuming) was to write a VS AddIn app to manipulate my proxy files
generated with wsdl based on parameters I want to alter (ie -- adding DEBUG
flag, overrides, etc...). I know this probably isn't the solution you're
looking for but, once it is set up, it is easy to maintain. There might
even be a good, free tool that does this -- I haven't checked in a couple
years.

Alex
 
D

Dmitry Kostenko

Hi, Benne

You should be able to inherit from the classes to override necessary methods (like ToString()) and
constructors. Isn't it true?
 
S

Sami Vaaraniemi

Modifying generated web service proxies is almost always a bad idea, as
you've already discovered yourself. There are ways to handle this situation
that are better than modifying the proxy code.

First off, you can make the proxies dynamic instead of static (the 'URL
Behavior' field in the properties of the proxy in VS.NET). You can then
provide the URLs through a config file.

Alternatively, you could derive a class from the proxy class. In the
constructor of the subclass, assign to the base class's Url property:

public class MyProxySubClass : WebServiceProxy
{
public void MyProxySubClass()
{
#if DEV
base.Url = "http://mydevserver/mywebservice/myservice.asmx";
#endif
#if TEST
base.Url = "http://mytestserver/mywebservice/myservice.asmx";
#endif
}
}

Then in your application you use the subclass instead of the generated proxy
class to access the web service. This way, if the proxy is regenerated you
do not lose the changes.

Finally, it is also possible to write your own web service proxy generator.
This is admittably a bit more work but not impossibly so as .NET provides
much of the plumbing (see the ServiceDescriptionImporter class).

hth,
Sami
www.capehill.net
 
B

Benne Smith

Sami, thanks for your reply ! It's a very good idea to make a "wrapper"
class around the proxy, so i can keep my manually edited things. Cheers !
Why didn't I think of that ?? :)

Then the only thing I need would be to create a AddIn to generate all proxy
classes, based on the active configuration (Development, Test, Production),
then it should work !

Thanks.

:) Benne Smith
 
B

Benne Smith

Dmitry, yes it's correct. Also "Sami" answered this in another post.

However, now my problem is how to access my Compiler Constants from inside a
macro/addin ! Do you have any idea how to do that ?? (I've made another
posting today about this).
 

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

Top