Этого кода должно быть достаточно для начала работы:
Form1.cs
namespace TestWinform
{
public partial class Form1 : Form
{
private ServiceHost Host;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Host = new ServiceHost(typeof(MyWcfService));
Host.Open();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Host.Close();
}
}
}
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="TestWinform.MyWcfServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="TestWinform.MyWcfServiceBehavior"
name="TestWinform.MyWcfService">
<endpoint address="" binding="wsHttpBinding" contract="TestWinform.IMyWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MyWcfService/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Обратите внимание, что App.config был сгенерирован Visual Studio, когда я добавил службу WCF в свой проект.