2011-10-25 3 views
3

Comment voulez-vous configurer les services de données WCF suivants couramment en C#?Comment configurer par programme les services de données 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> 

Répondre

5

Ce qui suit configure un DataServiceHost équivalent, à l'écoute sur le point final 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; 
} 
Questions connexes