如何以编程方式配置WCF数据服务?

发布于 2024-12-11 17:15:37 字数 858 浏览 0 评论 0原文

您将如何使用 C# 流畅地配置以下 WCF 数据服务?

<configuration>

  ...

  <system.serviceModel>
    <services>
      <service name="Foo.WebServices.FooService">
        <endpoint address="http://localhost:8081/PhoenixData" 
                  binding="webHttpBinding" 
                  bindingConfiguration=""
                  contract="System.Data.Services.IRequestHandler" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>  
</configuration>

How would you configure the following WCF Data Services fluently in C#?

<configuration>

  ...

  <system.serviceModel>
    <services>
      <service name="Foo.WebServices.FooService">
        <endpoint address="http://localhost:8081/PhoenixData" 
                  binding="webHttpBinding" 
                  bindingConfiguration=""
                  contract="System.Data.Services.IRequestHandler" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>  
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薯片软お妹 2024-12-18 17:15:37

下面将配置一个等效的 DataServiceHost,监听端点 uri

DataServiceHost CreateServiceHost(Uri uri)
{
    var host = new DataServiceHost(typeof(FooDataService), new Uri[] { });

    // these may need to be added if they don't already exist.
    host.Description.Behaviors.Find<ServiceMetadataBehavior>().HttpGetEnabled = true;
    host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;

    host.AddServiceEndpoint(
        new ServiceEndpoint(ContractDescription.GetContract(typeof(FooDataService)))
            {
                Name = "default",
                Address = new EndpointAddress(uri),
                Contract = ContractDescription.GetContract(typeof(IRequestHandler)),
                Binding = new WebHttpBinding()
            });

    return host;
}

The following will configure an equivalent DataServiceHost, listening on endpoint uri.

DataServiceHost CreateServiceHost(Uri uri)
{
    var host = new DataServiceHost(typeof(FooDataService), new Uri[] { });

    // these may need to be added if they don't already exist.
    host.Description.Behaviors.Find<ServiceMetadataBehavior>().HttpGetEnabled = true;
    host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;

    host.AddServiceEndpoint(
        new ServiceEndpoint(ContractDescription.GetContract(typeof(FooDataService)))
            {
                Name = "default",
                Address = new EndpointAddress(uri),
                Contract = ContractDescription.GetContract(typeof(IRequestHandler)),
                Binding = new WebHttpBinding()
            });

    return host;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文