2012-03-27 27 views
4

Ich versuche, diesen Dienst unter zu hosten, der gut läuft, aber wenn ich ein neues Projekt in einer anderen Visual Studio Runtime öffne und versuche, einen Webdienst hinzuzufügen, kann es nichts finden? Nicht an der angegebenen Adresse oder irgendetwas auf dem lokalen Rechner? Der folgende Code scheint nur zu funktionieren, wenn ich ihn in der gleichen Lösung verwende?Web-Service nicht erkannt?

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(); 
     } 
    } 


} 

Die Störung, die ich erhalte, wenn ich versuche, es von einem neuen Projekt (seperate der aktuellen Lösung) hinzuzufügen, ist dies:

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. 

, die, wenn ich diese Fallstudie (Starter-Projekt) es heruntergeladen Hatte keine Web- oder App-Konfigurationsdateien überall wo es gerade von den Konsolen-Apps gehostet wurde.

Beachten Sie auch, dass der Dienst ausgeführt wird, wenn ich versuche, den Webdienst hinzuzufügen.

+0

Sie sind also eine neue VS öffnen und versuchen, einen Dienstverweis auf 'http hinzuzufügen: // localhost: 8001' und es gibt Ihnen einen Fehler entdeckt? Was ist der Fehler? – CodingGorilla

+0

VS wird nach meinem Wissen nicht nur beliebige lokale Dienste automatisch erkennen, sondern nur den Teil einer Lösung. Haben Sie die URL in das Service-Referenz-Textfeld eingegeben? Hat es funktioniert? –

+2

Wird der Service-Host (die Konsolen-App) beim Hinzufügen eines Serviceverweises von einem anderen Projekt ausgeführt? – daryal

Antwort

3

hinzufügen Metadatenaustausch Verhalten in Ihrem 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