I have this configuration in my app.config:
</binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="myBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors>
I want to deploy this service programmatically from my desktop application:
I define the host instance:
ServiceHost host = new ServiceHost(typeof(MyType), new Uri("http://" + hostName + ":" + port + "/MyName"));
Then I add the anchor endpoint:
var binding = new BasicHttpBinding("myBinding"); host.AddServiceEndpoint(typeof(IMyInterface), binding, "MyName");
Now I want to replace the following code with code that reads a behavior named myBehavior from the configuration file, rather than hard-coded behavior parameters.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior() { HttpGetEnabled = true }; host.Description.Behaviors.Add(smb); // Enable exeption details ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>(); sdb.IncludeExceptionDetailInFaults = true;
Then I can open the host.
host.Open();
* EDIT *
Configuring Services Using Configuration Files
You do not need to do this, you must make sure that the host automatically accepts the configuration from the configuration file and does not give them manually, read this article (Configuring services using configuration files) , this will help you, I placed my service on one line in C # and several of them in the configuration.
This is the second article on (Configuring WCF Services in Code) , my mistake is that I tried to mix two paths!
I will add this as an answer.