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

  • Home
  • SEARCH
  • 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 1045743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:01:59+00:00 2026-05-16T16:01:59+00:00

I am trying to host WCF serviec in managed Windows Service. Basically i have

  • 0

I am trying to host WCF serviec in managed Windows Service. Basically i have 1 solution CustomersWCFLibrary which contains 3 Projects.

1) CustomersWCFLibrary :-

This is my app.config :-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
  </configSections>
  <connectionStrings>
    <add name="CustomersWCFLibrary.Properties.Settings.NorthWindConnectionString"
      connectionString="Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>

    <services>
      <service  name="CustomersWCFLibrary.CustomersService" behaviorConfiguration="ServiceBehavior">
        <endpoint  address="net.tcp://localhost:9000/CustomersService" binding="netTcpBinding" contract="CustomersWCFLibrary.ICustomersService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:9001/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="false"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

My class :-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace CustomersWCFLibrary
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class CustomersService : ICustomersService
    {
        public List<Customers> GetAllCustomers()
        {
            List<Customers> customersList = new List<Customers>();
            using (SqlConnection objSqlConnection = new SqlConnection(Properties.Settings.Default.NorthWindConnectionString))
            {
                objSqlConnection.Open();
                SqlCommand objSqlCommand = new SqlCommand("Select CustomerID, ContactName, ContactTitle,CompanyName,Address from Customers",objSqlConnection);
                SqlDataReader objSqlDataReader =  objSqlCommand.ExecuteReader();

                while (objSqlDataReader.Read())
                {
                    string customerID = objSqlDataReader.GetString(0);
                    string contactName = objSqlDataReader.GetString(1);
                    string contactTitle = objSqlDataReader.GetString(2);
                    string companyName = objSqlDataReader.GetString(3);
                    string Address = objSqlDataReader.GetString(4);
                    Customers objCustomers = new Customers();
                    objCustomers.CustomerId = customerID;
                    objCustomers.ContactName = contactName;
                    objCustomers.ContactTitle = contactTitle;
                    objCustomers.CompanyName = companyName;
                    objCustomers.Address = Address;

                    customersList.Add(objCustomers);
                }
            }
            return customersList;
        }
    }
}

My contract :-

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

namespace CustomersWCFLibrary
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface ICustomersService
    {
        [OperationContract]
        List<Customers> GetAllCustomers();


        // TODO: Add your service operations here
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class Customers
    {

        [DataMember]
        public string CustomerId
        { get; set; }

        [DataMember]
        public string ContactName
        {get; set;}

         [DataMember]
        public string ContactTitle
        {get; set;}

         [DataMember]
        public string CompanyName
        {get; set;}

         [DataMember]
        public string Address
        {get; set;}


    }
}

2) CustomersWindowsService

App.config :-

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="CustomersWCFLibrary.CustomersService">

                <endpoint address="net.tcp://localhost:9000/CustomersService" 
                          binding="netTcpBinding"
                    bindingConfiguration="" name="CustomersService_Tcp" contract="CustomersWCFLibrary.ICustomersService" />

            </service>
        </services>
    </system.serviceModel>
</configuration>

This is my code of windows service :-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;

namespace CustomersWindowsService
{
    public partial class CustomersServiceWinService : ServiceBase
    {

        private ServiceHost host = null;

        public CustomersServiceWinService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {

                host = new ServiceHost(typeof(CustomersWCFLibrary.CustomersService));
                host.Open();

        }

        protected override void OnStop()
        {
            host.Close();
        }
    }
}

3) My Console Application WCFCustomersTest

App.Config :-

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings />
        <client>
            <endpoint address="net.tcp://localhost:9000/CustomersService"
                binding="netTcpBinding" bindingConfiguration="" contract="CustomersWCFLibrary.ICustomersService"
                name="CustomersService_Tcp" kind="" endpointConfiguration="" />
        </client>
    </system.serviceModel>
</configuration>

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;


namespace WCFCustomersTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var channel = new ChannelFactory<CustomersWCFLibrary.ICustomersService>("CustomersService_Tcp").CreateChannel();
            List<CustomersWCFLibrary.Customers> objList = channel.GetAllCustomers();
            Console.Write(objList.Count);
            Console.Read();

        }
    }
}

My console application contains reference to my WCFClassLibrary(1st Project).

1) If i do not start my Windows Service and run it in VS 2010, i get the proper output . But if i run my application from outside the VS, i get a very long strange exception.

2) If i start my Windows Service and i try to run my application from within VS or outside VS i get this error :-

System.ServiceModel.FaultException was unhandled
  Message=The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
  Source=mscorlib
  Action=http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at CustomersWCFLibrary.ICustomersService.GetAllCustomers()
       at WCFCustomersTest.Program.Main(String[] args) in C:\Users\abc\documents\visual studio 2010\Projects\CustomersWCFLibrary\WCFCustomersTest\Program.cs:line 15
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

I am trying to solve this mistake since 3 hours without any success.

Thanks in advance 🙂

  • 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-16T16:02:00+00:00Added an answer on May 16, 2026 at 4:02 pm

    I would suggest two things for troubleshoting the issue,

    1. Enable includeExceptionDetailInFaults, to get more details on the response.
    2. Enable the WCF tracing, as you probably will find more details in the trace.

    I will able to help more if I can see more details about the error. That error you posted there, is a generic one.

    Thanks
    Pablo.

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

Sidebar

Related Questions

I'm trying to host a WCF Service inside a Windows Service which I am
I am trying to host a WCF service on a windows service.Basically WCF service
I have a WCF service. I am trying to host the service in a
I have a simple test purpose WCF service. I'm trying to host it under
I have WCF service hosted by Windows service. This is my app.config file (server-side)
When trying to host my WCF service using Net Tcp channel through Windows Console,
I am trying to host a WCF service, using NetTcpBinding in a Windows service.
I am trying to host a WCF web service in IIS using Windows Authentication.
I am totally new to this and trying to host the simplest WCF service
I'm running Windows 7 64-bit. I'm attempting to host a WCF service which will

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.