Alexander Grasberger
Alexander Grasberger

Reputation: 356

Calling function of self hosted wcf service

I am new to WCF and hosting a WCF service in a Console Application where i now want to call a function inside the service.

Program.cs:

static void Main(string[] args)
{
    var host = new ServiceHost(typeof(TestService));
    host.Open();
    Console.WriteLine("Service started at {0}", DateTime.Now);
    Console.ReadLine();
    host.Close();
}

The TestService contains a function that i want to call now.

App.config:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="TestServer.TestService">
        <endpoint address="" binding="wsDualHttpBinding" contract="TestServer.ITestService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8090/TestService/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

I found out that i have to user a ChannelFactory, but i have no idea how to implement it into my code so it works.

Upvotes: 2

Views: 2161

Answers (1)

Alexander Grasberger
Alexander Grasberger

Reputation: 356

I finaly found a nice example on how to use the ChannelFactory so that everything works fine. http://www.c-sharpcorner.com/UploadFile/ff2f08/channel-factory-in-wcf/

Upvotes: 2

Related Questions