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 have a WCF service which has two methods exposed: Note: The wcf service
So, I have a method exposed from a WCF service as such: public GetAllCommentsResponse
I have a WCF Service Library exposed through my ASPX site as follows [System.ServiceModel.OperationContract]
I have my WCF service hosted as Windows Service and all the exposed methods
I have a WCF service with many methods. I would like that after executing
I have some special parameters to all my wcf service methods that are handled
I have one test wcf service with default methods and web config is :
I'm hosting my first WCF service in IIS. I have two methods, 1 to
Suppose I want to create a (stateless) WCF service with three methods exposed on
I have a WCF web service that exposes several business methods. I also 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.