Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. How to do Constructor Overloading in WCF Service class

How to do Constructor Overloading in WCF Service class

Scheduled Pinned Locked Moved WCF and WF
csharpvisual-studiowcfhelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tiger456
    wrote on last edited by
    #1

    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.

    D S 2 Replies Last reply
    0
    • T Tiger456

      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.

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Here is a link[^] that explains how to use parameterized constructors in WCF.

      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...!!

      T 1 Reply Last reply
      0
      • D dan sh

        Here is a link[^] that explains how to use parameterized constructors in WCF.

        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...!!

        T Offline
        T Offline
        Tiger456
        wrote on last edited by
        #3

        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 ..

        D 1 Reply Last reply
        0
        • T Tiger456

          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 ..

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          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...!!

          1 Reply Last reply
          0
          • T Tiger456

            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.

            S Offline
            S Offline
            Sir Dot Net
            wrote on last edited by
            #5

            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[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups