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 7512937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:01:24+00:00 2026-05-30T00:01:24+00:00

Making a small WCF test program which is based on a Store that has

  • 0

Making a small WCF test program which is based on a Store that has customers and each customer has a balance of special points. For now I want to focus on having a fixed number of customers, say 3. Problem is I can’t wrap my head around where would I create those customers and how would I access them from the service’s functions. I was thinking of creating an array of customers inside main() of the service so that they are available to the client later on, but is it a good idea? Very fresh to WCF and couldn’t find any examples that would show how to implement something like that.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.ServiceModel.Description;

namespace StoreService
{

    public class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:6112/StoreService");
            ServiceHost host = new ServiceHost(typeof(Store), baseAddress);
            try
            {
                host.AddServiceEndpoint(typeof(IStore), new WSHttpBinding(), "Store");
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                host.Description.Behaviors.Add(smb);
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();
                host.Close();

            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occured: {0}", ce.Message);
                host.Abort();
            }
        }
    }

    [ServiceContract(Namespace="http://StoreService")]
    public interface IStore
    {
        [OperationContract]
        void AddPoints(string accNum, double points);

        [OperationContract]
        void SubtractPoints(string accNum, double points);

        [OperationContract]
        int CustomerPoints(string accNum);
    }

    [DataContract]
    public class Customer
    {
        private string accountNumber;
        private string name;
        private double points;

        [DataMember]
        public int AccountNumber
        {
            get { return accountNumber; }
            set { accountNumber = value; }
        }

        [DataMember]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        [DataMember]
        public int Points
        {
            get { return points; }
            set { points = value; }
        }
    }


    public class Store : IStore
    {
        public void AddPoints(string accNum, double points)
        {
            //Add points logic
        }

        public void SubtractPoints(string accNum, double points);
        {
            //Substract points logic
        }

        public int CustomerPoints(string accNum)
        {
            //Show points
        }
    }
}
  • 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-30T00:01:26+00:00Added an answer on May 30, 2026 at 12:01 am

    Your going to need an Interface to your service and the code for each of the methods exposed by your service.

    This is off the top of my head, untested, the Microsoft examples will show you this stuff posted by Bryan

    For example, add 2 new classes:

    // First the Interface, things in here decorated with the Operation contract gets exposed, things with serializable are available to the client
    
    namespace MyService
    {
        [ServiceContract]
        public interface ICustomer
        {
    
            [OperationContract]
            int GetBalance(Guid CustomerId);
        }
    
        [Serializable]
        public class Customer
        {
            public Guid Id;
            public int Balance;
        }
    }
    
    
    
    
    // 2nd class file is the code mapping to the interface
    namespace MyService
    {
        private List<Customer> Customers = new List<Customer>();
        public class MyService : ICustomer
        {
            public int GetBalance(Guid CustomerId)
            {
                foreach(Customer c in Customers)
                {
                     if(c.Id == CustomerId)
                     {
                         return c.Balance;
                     }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a small program using C++/CLI that use TcpListener , I know
I am making a small program in C# for Windows Phone. One thing that
I'm making a small tool application that user can minimize in the taskbar .
I am making some small business intelligence applications/tools that need to talk to other
i am making a small project which will be incorporated into larger project. basically
I'm making small program for socket communication in C#. Here're my codes: Client (data
I am making a small project for myself that deals with gps and some
I am making a small app that lets users vote items either up or
I'm making a small asp.net mvc app. in which I have to compute data
I'm making a small application that is supposed to download info from the web

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.