Click here to Skip to main content
Click here to Skip to main content

WCF and Windows Services: Object Initialization of WCF Client Proxy Takes Too Much Time

, 7 Jul 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
How to avoid delay in Object Initialization of WCF client proxy in a Window service

Introduction

Today, every application is expected to be run on its own without the help of users, and window services provide a solution to that problem. Also in distributed environment, WCF provides an almost perfect solution for network calls and data transfer. When both are used together, it provides benefits in many cases.

But when in Window Service, WCF Client object is initialized, it may happen that it takes times to be initialized (usually it takes 15-20 second). Developer may think that network is causing the delay. But the actual problem lies with the Windows 7 user rights. When we initialize the object, it actually establishes a collection over the network to secure a communication passage, but it requires authentication. WCF provides its own level of authentication and user can change its setting via CONFIG file, but it does not serve the purpose in all cases. Windows Service is one such case when an extra level of authentication is performed by the application.

Problem: Object Initialization takes too much time by WCF object initialization in a Windows service application.

Assumption: Developer has basic knowledge of WCF client Proxy and Window Services.

Using the Code

Suppose I have Contract ConCat and I have added its proxy reference to a project which is being used inside a Window Service project.

ContractConcat.ConcatClient obj = new ContractConcat.ConcatClient();

App.Config contains:

   <client>
            <endpoint address="http://127.0.0.1:4040/ServerCode" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IConcat" contract="ContractConcat.IConcat"
                name="WSHttpBinding_IConcat">
                <identity>
                    <userPrincipalName value="AnantBeriwal-PC\Anant Beriwal" />
                </identity>
            </endpoint>
   </client>

User may experience a wait of several seconds in this single point of statement. The call to initialize object of WCF client will wait until window does not authenticate it. However, this can be skipped. User only has to provide proper rights to Windows Service.

Solution

The problem lies with the privileges that are being set by OS on the Windows services. WCF has its own authentication but windows service requires separate authentication if a network connection is established.

Providing User Rights

  1. Go to Run window.
  2. Type Service.msc, press OK.
  3. Select your service, right click on it, select Properties.
  4. On second tab, "Log On", select option this account.
  5. Type your current user (or admin user) credentials, then click apply.

Window Service Properties

That's all folks. Have a good day.

License

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

Share

About the Author

Anant Beriwal
Software Developer
India India
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 8 Jul 2014
Article Copyright 2014 by Anant Beriwal
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid