How to do Constructor Overloading in WCF Service class
-
Is there any way to call overloaded constructor in WCF. This is the way i did it . 1. Created an overloaded constructor in service
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class CustomerService : ICustomerService
{
private string _UserName = string.Empty;public CustomerService (string userName) { \_UserName = userName; }
}
2. Added Service reference using Visual studio "
Service Reference
" option 3.CustomerServiceClient pxy = new CustomerServiceClient("sam"); // Error
This overloaded constructor is not exposed over here . Not sure wheather i am following the right way. it would be great if you people can direct me to the solution.
-
Is there any way to call overloaded constructor in WCF. This is the way i did it . 1. Created an overloaded constructor in service
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class CustomerService : ICustomerService
{
private string _UserName = string.Empty;public CustomerService (string userName) { \_UserName = userName; }
}
2. Added Service reference using Visual studio "
Service Reference
" option 3.CustomerServiceClient pxy = new CustomerServiceClient("sam"); // Error
This overloaded constructor is not exposed over here . Not sure wheather i am following the right way. it would be great if you people can direct me to the solution.
-
-
Thanks for your reply. i want to add this to an existing code. just adding it to constructor. Could you help me to copy the only needed code and copy update my code. I haven't got the exact idea of the above one ..
I am afraid it won't be just copy paste. You will need to add a behavior to your service that will inturn make use of the class implementing IInstanceProvider. You will also need to add this class to your service. You will need to update the config file with this behavior since it won't show there by default. You will need to update the way your client is consuming the service. If you spend some time with that code and read about IServiceBehavior and IInstanceProvider interface, I hope you will understand.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
Is there any way to call overloaded constructor in WCF. This is the way i did it . 1. Created an overloaded constructor in service
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class CustomerService : ICustomerService
{
private string _UserName = string.Empty;public CustomerService (string userName) { \_UserName = userName; }
}
2. Added Service reference using Visual studio "
Service Reference
" option 3.CustomerServiceClient pxy = new CustomerServiceClient("sam"); // Error
This overloaded constructor is not exposed over here . Not sure wheather i am following the right way. it would be great if you people can direct me to the solution.
The alternative is redesigning your service to use WCF sessions. You can create an operation that is starts the session, while marking others as unable to be called until the 'IsInitializing' operation is called first. Once you understand how WCF sessions work, you'll see they are a very powerful mechanism for controlling the call flow to your service. Generally, parameterized constructors for WCF services is discouraged (see IDesign's WCF Code Standards, great document). You can find out more about WCF sessions here: http://msdn.microsoft.com/en-us/library/ms733040.aspx[^]