通过代码配置WCF kind =“webHttpEndpoint”

时间:2011-12-22 21:28:48

标签: wcf rest configuration

我有一个WCF服务,它在类PosData.ISampleService中实现接口PosData.SampleService。该服务是自托管的,启动代码如下所示:

ServiceHost serviceHost = new ServiceHost(typeof(SampleService), new Uri("http://localhost:8080/sample"));
serviceHost.Open();
Console.WriteLine("Service started.");
Console.ReadLine();

app.config包含以下行:

<services>
  <service name="PosData.SampleService">
    <endpoint address="http://localhost:8080/sample" contract="PosData.ISampleService" kind="webHttpEndpoint"/>
  </service>
</services>

我想摆脱App.config配置,但我不知道如何通过代码配置webHttpEndpoint。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

使用WebServiceHost而不是ServiceHost。