Nahum
Nahum

Reputation: 7197

how to hard code WCF config?

I try to create hard coded wcf service (no app.config) I tried the following

service = new CommService.TwService();

localHost = new ServiceHost(service);

ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
localHost.Description.Behaviors.Add(behavior);

localHost.AddServiceEndpoint(typeof(IMetadataExchange),
     MetadataExchangeBindings.CreateMexNamedPipeBinding(),
     "net.pipe://localhost/service/mex/");

localHost.Open();

fails with :

Service 'CommService.TwService' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

Upvotes: 2

Views: 704

Answers (1)

Kinexus
Kinexus

Reputation: 12904

You have only added an endpoint for Mex, which will not expose the service itself. You need to add another binding explicitly for the service implementation, for example;

WSHttpBinding binding = new WSHttpBinding();
localHost.AddServiceEndpoint(typeof(CommService.TwService), binding, "http://localhost/service");

Upvotes: 3

Related Questions