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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:09:50+00:00 2026-05-20T06:09:50+00:00

I have an existing application which now has the requirement to be interacted with

  • 0

I have an existing application which now has the requirement to be interacted with from a mobile device. The mobile device has a wifi connection, and would be connecting to the PC hosting the main application on a LAN. The mobile device simply needs to add/edit/find/delete objects the main application is maintaining. The main application already encapsulates his functionality in some simple repository classes.

I believe the approach would be to add a WCF service to the main application which exposes a set of methods the mobile device can call against. However I have looked up WCF today and tried to setup an example application, but when called the WCF methods it is unable to access any data, as such I feel the WCF service is running in its own application domain and as such has no access to the same static classes in the main application.

If I setup a WCF service project in VS 2008/2010, how can I run it under the same application domain as the main WinForms application, so that a remote application on the LAN can communicate with it to get data from the application.

Below is my sample WinForm

using System;
using System.ServiceModel;
using System.Windows.Forms;
using DataProject;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public TestDataProject.DataStore Datastore = TestDataProject.DataStore.GetInstance();

        public Form1()
        {
            InitializeComponent();
            Datastore.Add(new MyObj { ID = 1, Data = "hello" });
            Datastore.Add(new MyObj { ID = 2, Data = "world" });
            Datastore.Add(new MyObj { ID = 3, Data = "item3" });
            Datastore.Add(new MyObj { ID = 4, Data = "item4" });
            Datastore.Add(new MyObj { ID = 5, Data = "fiver" });
        }
    }
}

What I need from a WCF service, is access to TestDataProject.DataStore.GetInstance();

Edit

I achieved this by

using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Windows.Forms;
using DataProject;
using TestDataProject;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public TestDataProject.DataStore Datastore = TestDataProject.DataStore.GetInstance();

        public Form1()
        {
            InitializeComponent();
            Datastore.Add(new MyObj { ID = 1, Data = "hello" });
            Datastore.Add(new MyObj { ID = 2, Data = "world" });
            Datastore.Add(new MyObj { ID = 3, Data = "item3" });
            Datastore.Add(new MyObj { ID = 4, Data = "item4" });
            Datastore.Add(new MyObj { ID = 5, Data = "fiver" });

            ServiceHost host = new ServiceHost(typeof(SimpleService),
                new Uri("http://localhost:8001/MetadataSample"));
            try
            {
                // Check to see if the service host already has a ServiceMetadataBehavior
                ServiceMetadataBehavior smb = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
                // If not, add one
                if (smb == null)
                    smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);
                // Add MEX endpoint
                host.AddServiceEndpoint(
                  ServiceMetadataBehavior.MexContractName,
                  MetadataExchangeBindings.CreateMexHttpBinding(),
                  "mex"
                );
                // Add application endpoint
                host.AddServiceEndpoint(typeof(ISimpleService), new WSHttpBinding(), "");

                // Open the service host to accept incoming calls
                host.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                //host.Close();
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message);
                Console.Read();
            }

        }

        public void Display(string msg)
        {
            MessageBox.Show(msg);
        }
    }

    [ServiceContract]
    public interface ISimpleService
    {
        [OperationContract]
        string Test();

        [OperationContract]
        string GetOBJDesc(int id);

        [OperationContract]
        MyObj GetObject(int id);
    }

    public class SimpleService : ISimpleService
    {
        #region Implementation of ISimpleService

        public string Test()
        {
            return "Hello world";
        }

        public string GetOBJDesc(int value)
        {
            MyObj obj = DataStore.GetInstance().Get(value);
            if (obj != null)
            {
                return obj.Data;
            }
            return "";
        }

        public MyObj GetObject(int id)
        {
            return DataStore.GetInstance().Get(id);
        }

        #endregion
    }
}

With app.config containing

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="WindowsFormsApplication1.SimpleService">
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SimpleServiceBehavior">
          <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

I could then use WCF Test Client on the url http://localhost:8001/MetadataSample

The main issue I suffered from was my Service starting automatically, this can be disabled in VS2010 by a project setting. And the other issue was UAC, given Visual studio was not set to be a administrator the debugger failed to host a service, this was fixed by adding a WindowsFormApplication1.MANIFEST file containing

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">”
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">”
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>
  • 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-20T06:09:50+00:00Added an answer on May 20, 2026 at 6:09 am

    You have created a WCF Web Service project, which will be running inside the web service process (normally IIS), not inside your windows forms process and so it won’t have any access to any data in static classes and properties in the Windows Forms process.

    It sounds like your simplest option is to host the WCF service inside your windows forms application instead. I don’t want to go into too much detail on how to do this as there are a number of resources already available on the web (also I can hardly claim to be an expert!), but you might want to try the following article as a starting point:

    • Hosting WCF services in a Windows Forms Application
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing WinForms application for which I'm now designing new bits in
Suppose I have logged into an application which is running from IIS . Now
Let's say I have an existing application written in Java which I wish to
Time ago I created an application which has some buttons in the form. Now
I have an existing application that is written in C++ for Windows. This application
I'm supporting an existing application written by another developer and I have a question
(Eclipse 3.4, Ganymede) I have an existing Dynamic Web Application project in Eclipse. When
We have an existing publicly accessible web application with user controls, data access libraries,
I have an existing SQL Server 2005 database that runs our accounting/inventory application. We
I am implementing NHibernate into an existing web application. However, we have some other

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.