Web service not found?

I am trying to host this service, below which it works fine, but when I open a new project in a different visual studio environment and try to add a web service, it cannot find anything? Not at the specified address or something on the local machine? The code below seems to work when I run it in the same solution?

namespace Students { class Program { static void Main(string[] args) { // Create the address for the service Uri address = new Uri("http://localhost:8001"); // Create the binding for the service WSHttpBinding binding = new WSHttpBinding(); // Create the service object StudentService service = new StudentService(); // Create the host for the service ServiceHost host = new ServiceHost(service, address); // Add the endpoint for the service using the contract, binding and name host.AddServiceEndpoint(typeof(IStudentService), binding, "students"); // Open the host host.Open(); Console.WriteLine("Student service started"); Console.WriteLine("Press return to exit"); Console.ReadLine(); // Close the host host.Close(); } } } 

The error I get when I try to add it from a new project (separately to the current solution):

 The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'http://localhost:8001/'. There was no endpoint listening at http://localhost:8001/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found. If the service is defined in the current solution, try building the solution and adding the service reference again. 

That when I downloaded this study (starter project), it didn’t have any configuration files on the Internet or the application at any place where it had just been located from console applications.

Also note that my service is running when I try to add a web service.

+4
source share
2 answers

Add Exchange metadata behavior to your ServiceHost.

 namespace Students { class Program { static void Main(string[] args) { // Create the address for the service Uri address = new Uri("http://localhost:8001"); // Create the binding for the service WSHttpBinding binding = new WSHttpBinding(); // Create the service object StudentService service = new StudentService(); // Create the host for the service ServiceHost host = new ServiceHost(service, address); // Add the endpoint for the service using the contract, binding and name host.AddServiceEndpoint(typeof(IStudentService), binding, "students"); // Add metadata exchange ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; host.Description.Behaviors.Add(smb); // Open the host host.Open(); Console.WriteLine("Student service started"); Console.WriteLine("Press return to exit"); Console.ReadLine(); // Close the host host.Close(); } } } 

http://wcftutorial.net/WCF-Self-Hosting.aspx

+3
source

You will need to create / update the app.config file with information about your service. Check out: http://msdn.microsoft.com/en-us/library/ms734765.aspx

Read more here: fooobar.com/questions/517557 / ...

+1
source

Source: https://habr.com/ru/post/1403693/


All Articles