vineet sharma

vineet sharma

  • NA
  • 22
  • 21.2k

error in wcf while opening the servicehost

Mar 26 2014 2:53 AM
here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;


namespace EmployeeServiceHost
{
    class Program
    {
        static void Main()
        {
            using (ServiceHost host = new ServiceHost(typeof(EmployeeServices.EmployeeService)))
            {
                try
                {
                    host.Open();
                    Console.WriteLine("SERVER STARTED @: " + DateTime.Now.ToString());
                    Console.ReadLine();
                }
                catch(Exception er)
                {
                    Console.WriteLine(er.ToString());
                }
                finally
                {
                    host.Close();
                }
            }
        }
    }
}

and my app.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <services>
      <service name="EmployeeServices.EmployeeService" behaviorConfiguration="mexBehaviour">
        <endpoint address="EmployeeServices" binding="basicHttpBinding" contract="EmployeeServices.IEmployeeService"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

error i m getting is 
An unhandled exception of type 'System.ServiceModel.CommunicationObjectFaultedException' occurred in System.ServiceModel.dll

Additional information: The communication object, System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state.



thanks in advance





Answers (1)