Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 422547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:05:31+00:00 2026-05-12T19:05:31+00:00

I have a WCF service and methods are exposed as below: public interface IService

  • 0

I have a WCF service and methods are exposed as below:

public interface IService
{
   [OperationContract]
   bool Read();
   [OperationContract]
   bool Write();
}

public class MyService : IService
{

    //Constructor

    MyService()
    {
        //Initialization
    }

    public bool Read()
    {
        //Definition
    }

    public bool Write()
    {
        //Definition
    }
}

I have a desktop based application that consumes the Web service through URL.
This web service can be deployed at multiple location so user can connect to any web service by choosing a url from the combo box.

In the client application I create a Service client dynamically as shown below:

ServiceReference1.DXMyServiceClient _client = null;

_client = new DXMyServiceClient ();

_client.Endpoint.Address = new System.ServiceModel.EndpointAddress(url);

Questions
While debugging I notice whenever I call any methods of web service each time the constructor of MyService is invoked ( if I am connected to the same service).

like for example when I do:

_client.Read();//MyService () constructor is called 

_client.Write();//MyService () constructor is called 

The problem is I have to do all the initialization again.. like if I connecting to the database then I have to again build the connection string and all stuff..

Is this the natural behavior or I am doing something wrong?

Secondly,
I want to validate user for the valid url ( of web service ). If it is connecting to the valid url or not.. I am doing that through Ping command..
What is the best approach for that!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:05:32+00:00Added an answer on May 12, 2026 at 7:05 pm

    Questions While debugging I notice whenever I call any methods
    of web service each time the constructor of MyService is invoked
    (if I am connected to the same service).
    The problem is I have to do all the initialization again..
    like if I connecting to the database then I have to again
    build the connection string and all stuff..

    Yes, that’s the default behavior, and the recommended behavior. You should NOT rely on any state on your service side! That is generally not a good idea and can lead to a multitude of problems.

    In its recommended “per-call” mode, a WCF service has a ServiceHost() class instance running, which will listen for incoming requests / messages. Each time a request comes in, a new, fresh instance of the service class (that implements your service contract) is constructed to handle the request – just like each time you hit a URL in ASP.NET, your page class is instantiated to handle the request.

    Yes, of course – this means you should keep your service classes simple and lean and not do a lot of initialization / state management. Anything that needs to be persisted between service calls should be put in a persistence store, like a database, anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm hosting my first WCF service in IIS. I have two methods, 1 to
I have a WCF Service that exposes a method GetCustomers(). The internals of the
I have a WCF service that I have to reference from a .net 2.0
I have a WCF service hosted for internal clients - we have control of
I have a WCF service and I want to expose it as both a
I have a WCF service running on the IIS with a ServiceHostFactory. It's running
I have a WCF service, hosted in IIS 7.0 that needs to run database
I have a WCF service with the following configuration: <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=MetadataEnabled>
I have a WCF Service that should not enter the faulted state. If there's
I have a WCF service which will be hosted under IIS. Now I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.