2012-03-27 2 views
4

다른 비주얼 스튜디오 런타임에서 새 프로젝트를 열고 아무것도 찾을 수없는 웹 서비스를 추가하려고하면 잘 실행되는이 서비스를 호스팅하려고합니까? 지정된 주소가 아니거나 로컬 시스템의 항목이 아닙니까? 아래 코드는 동일한 솔루션에서 실행할 때만 작동하는 것 같습니다.웹 서비스가 검색되지 않습니까?

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. 

나는이 사례 연구 (스타터 프로젝트)를 다운로드 할 때 어느 :

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


} 

나는 (현재의 솔루션에 대한 별도) 새로운 프로젝트를 추가 할 때 내가 오류는 이것이다 어디서나 콘솔 앱에서 호스팅되는 웹 또는 앱 설정 파일이 없습니다.

참고 웹 서비스를 추가하려고하면 서비스가 실행되고 있습니다.

+0

그래서 당신은 새로운 VS를 열고 HTTP'에 서비스 참조를 추가하려는 : // localhost를 : 8001'를하고 그것은 당신에게 오류를 준다? 오류가 무엇입니까? – CodingGorilla

+0

내 지식으로 VS는 자동으로 임의의 로컬 서비스를 자동으로 검색하지 않고 솔루션의 일부만 검색합니다. 서비스 참조 텍스트 상자에 URL을 입력 했습니까? 작동 했나요? –

+2

다른 프로젝트의 서비스 참조를 추가하는 동안 서비스 호스트 (콘솔 앱)가 실행 중이십니까? – daryal

답변

3

이 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

관련 문제