【问题标题】:How to programmatically configure WCF data services?如何以编程方式配置 WCF 数据服务?
【发布时间】:2011-10-25 15:35:33
【问题描述】:

您将如何在 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>

【问题讨论】:

    标签: wcf-data-services astoria


    【解决方案1】:

    下面将配置一个等效的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;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 2011-03-12
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 2010-10-20
      • 2011-01-04
      相关资源
      最近更新 更多