【问题标题】:Configure WCF kind="webHttpEndpoint" via code通过代码配置 WCF kind="webHttpEndpoint"
【发布时间】:2012-01-26 10:50:25
【问题描述】:

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

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。我该怎么做?

【问题讨论】:

    标签: wcf rest configuration


    【解决方案1】:

    使用 WebServiceHost 代替 ServiceHost。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-14
      • 2017-11-06
      • 2022-12-11
      • 1970-01-01
      相关资源
      最近更新 更多