Click here to Skip to main content
15,441,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have WebService which is referenced in C# ClassLibrary project.

In WebService project I have a class named User, which has two constructors - one without parameters and one whith parameters.

When I try to create instance of User class from WS in ClassLibrary, I can use only constructor with parameters.

My question is, how can I use in constructor with parameters like User u = new User("some@email.com", ...);.

Any idea? Thansk
Posted
Updated 3-Sep-10 0:31am
v2

Unfortunately, the Web service reference proxy class (That is generated when you add a reference to a web service) does not have any Constructor, even if the original class have at the service-end.

If you really want to use a constructor, go to the Class definition of the proxy class that is generated and add the constructor that you require (You can copy the constructor code from the original class at service-end)

Problem is, every time you update reference, your proxy class will be overwritten and you will lose your constructor code.

To overcome this limitation, instead of modifying the proxy class, you can write a partial class for User class in your client project that will contain the constructor. In this case, even if the proxy class is overwritten, the partial class will remain intact and you will always be able to use the constructor.

Best of luck :)
 
Share this answer
 
Comments
eridanix 3-Sep-10 8:16am     CRLF
I thought that :-( Thanks!
asdfasdfasdf
Mubahil
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900