I am trying to create a service host for my WCF application. When I launch the application, I get an error
The service cannot be started. This service does not have an endpoint. Add at least one endpoint for the service in the configuration file and try again.
I followed the PluralSight tutorial and this is the code I came up with
using System.ServiceModel; using FreedomService; namespace ConsoleHost { class Program { static void Main(string[] args) { var host = new ServiceHost(typeof(PeopleService)); host.AddServiceEndpoint(typeof (IPeopleService), new BasicHttpBinding(), "http://localhost:8080/people/basic"); host.AddServiceEndpoint(typeof(IPeopleService), new WSHttpBinding(), "http://localhost:8080/people/ws"); host.AddServiceEndpoint(typeof(IPeopleService), new NetTcpBinding(), "net.tcp://localhost:8081/people"); try { host.Open(); PrintServiceInfo(host); Console.ReadLine(); host.Close(); } catch (Exception e) { Console.WriteLine(e); host.Abort(); } } static void PrintServiceInfo(ServiceHost host) { Console.WriteLine("{0} is up and running with these endpoints:",host.Description.ServiceType); foreach (var endpoint in host.Description.Endpoints) { Console.WriteLine(endpoint.Address); } } } }
IPeopleService.cs
[ServiceContract] public interface IPeopleService { [OperationContract] string GetData(int value); [OperationContract] PersonType GetPersonById(int id); }
PeopleService.cs
public class PeopleService : IPeopleService, IDisposable { private ICollection<PersonType> People = new Collection<PersonType> {
app.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> </configuration>
servicelibrary app.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> <system.web> <compilation debug="true" /> </system.web> <system.serviceModel> <services> <service name="FreedomService.PeopleService"> <host> <baseAddresses> <add baseAddress = "http://localhost:8733/Design_Time_Addresses/FreedomService/basic/" /> </baseAddresses> </host> <endpoint address="" binding="basicHttpBinding" contract="FreedomService.IPeopleService"> <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
source share