Posted on 2012-09-10
Last Modified: 2012-09-12
Is it possible to create a single WCF client connection for each web user? If so, where do I create the WCF client object?

Note: Not a new WCF connection for each page.

P.S. Newbie on ASP.NET
Question by:Thomasian
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    I'm afraid your requirment isn't clear. Can you describe the environment in a bit more detail? What do you mean by "each web user" with respect to a WCF application?
    LVL 22

    Author Comment

    I already have a WCF server app which manages the business rules, users and roles.

    Now, I am going to create a web application which connects to the WCF server. The web server will have 3 pages.  A log-in page, a change password page, and the main page.

    The main page will have 2 gridviews to show statistical data and a few buttons which simply sends a command to the WCF server.

    Now, the first thing a user has to do is to log in on the Log-in page. I then have to create a connection to the WCF server to authenticate the data entered by the user. When authenticated, it will then be redirected to show the main page which shows some statistical data and some buttons.

    The statistical data will be updated regularly so I am thinking of a WCF callback when the data is updated. If not possible, maybe a timer to regularly check for updates.

    Now, can I create a single WCF connection throught the "session?" so that I won't have to connect/disconnect for every update/page request.
    LVL 14

    Assisted Solution

    You service implementation can be decorated with a ServiceBehavior attribute of which one of its properties is the InstanceContextMode.  This property expects one of three InstanceContextMode enumerations;

    PerSession (default mode)

    The PerSession InstanceContextMode creates a new InstanceContext object for each session.  If for example you had five concurrent users, each user would interact with a unique instance of your service.  Conversely the Single InstanceContextMode uses a single InstanceContext object for all sessions.

    From what you have mentioned, the default InstanceContextMode should provide the functionality you desire.  Have you implemented any of what you have mentioned above and if so, what is working and what is not working for you?

    LVL 22

    Author Comment

    Where do I create the WCF connection? On Global.asax?

    Is it possible to initiate callback to the client for update notification?
    LVL 14

    Accepted Solution

    Where do I create the WCF connection? On Global.asax
    I would create the connection only when needed, which I assume is on your main page.

    Is it possible to initiate callback to the client for update notification?
    It is possible, however, only netTcpBinding , namedPipeBinding and wsDualHttpBinding support callbacks due to the connectionless nature of HTTP.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now