views:

125

answers:

2

I have a vb.net solution with a web reference to a webservice. Now I need another property in the designer generated code. This has the drawback, that once you update the web reference, your added code will be overitten.

What is the best way to add a property to the class?

A: 

Derive a subclass from your web service proxy, then add all the properties you want to the subclass, then change your code to use instances of the subclass instead of the proxy directly.

Your proxy can now be regenerated as many times as you like, but your derived subclass with its extra code remains stable.

John Källén
This will not work when trying to assign a webservice-object to a subclassed object.
Louis Haußknecht
+2  A: 

Update the class to be a partial class (might already be from the code generation) and then create another code file in your solution which won't be overridden. In there create a partial class of the same name (in the same namespace) as the generated code and add the property to this. This will have the benefit of not being overridden when the web service code is regenerated.

When you call the generated code class you then should be able to access the property which you have added to the other part of the partial class.

Hope this helps.

WestDiscGolf
Okay, this was really helpful. Forgot about the use of partial classes, since i never use them normally.
Louis Haußknecht
No worries, glad it helped :-)
WestDiscGolf