2017-12-03 5 views
1

최근에 WCF로 작업하기 시작했습니다. 문제 해결 방법이 하나도 없습니다. 서비스 호스트를 사용하여 WCF 서비스를 시작하지만 브라우저에서 URI를 사용하면 서비스 계약이 표시되지 않고 ChannelFactory를 사용하여 URI에 연결하려고하면 예외가 발생합니다.WCF 오류 - 서비스 끝점을 얻을 수 없습니다.

Visual Studio 2017에서 프로젝트를 만들었고 config 파일에 아무 것도하지 않았으므로 기본 주소를 변경했습니다. 서비스 인터페이스와 구현 모두 루트 프로젝트 "폴더"에 있으며 방화벽과 심지어 내 바이러스 백신을 비활성화하려고 시도했지만 아무 것도 작동하지 않는 것 같습니다.

의 App.config :

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
    <system.serviceModel> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name=""> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
     <services> 
      <service name="TaskExecutor.Exec"> 
       <endpoint address="" binding="basicHttpBinding" contract="TaskExecutor.IExec"> 
        <identity> 
         <dns value="localhost" /> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
       <host> 
        <baseAddresses> 
         <add baseAddress="http://localhost:8001/TaskExecutor/Exec/" /> 
        </baseAddresses> 
       </host> 
      </service> 
     </services> 
    </system.serviceModel> 
</configuration> 

서비스 인터페이스 :

namespace TaskExecutor 
{ 
    [ServiceContract] 
    public interface IExec 
    { 
     [OperationContract] 
     void DoWork(); 
    } 
} 

서비스 구현 :

namespace TaskExecutor 
{ 
    public class Exec : IExec 
    { 
     public void DoWork() 
     { 
      Console.WriteLine("Doing work."); 
     } 
    } 
} 

프로그램 실행 서비스 :

using (ServiceHost host = new ServiceHost(typeof(Exec))) 
{ 
    host.Open(); 
    Console.WriteLine("exec service started at {0}", host.BaseAddresses[0]); 
} 

Console.WriteLine("Press any key to end..."); 
Console.ReadLine(); 
,

프로그램이 메시지를 표시 시작 후 :

EndpointAddress endpoint = new EndpointAddress("http://localhost:8001/TaskExecutor/Exec/"); 
BasicHttpBinding binding = new BasicHttpBinding(); 

ChannelFactory<IExec> channelFactory = new ChannelFactory<IExec>(binding, endpoint); 
IExec proxy = channelFactory.CreateChannel(); 

proxy.DoWork(); 

그리고 그것은 예외를 제공합니다 :

exec service started at http://localhost:8001/TaskExecutor/Exec/ 
Press any key to end... 

서비스 클라이언트 코드는 다음과

System.ServiceModel.EndpointNotFoundException occurred 
    HResult=0x80131501 
    Message=There was no endpoint listening at http://localhost:8001/TaskExecutor/Exec/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 

Inner Exception 1: 
WebException: Unable to connect to the remote server 

Inner Exception 2: 
SocketException: No connection could be made because the target machine actively refused it 
내가 심각하게 돈

를 ' 무엇을해야하는지 알며, 어떤 도움도 훌륭합니다.

대단히 감사합니다!

+0

는 WCF에 단계 튜토리얼에 의해 간단한 단계에서이 사이트로 이동 - – MethodMan

+0

덕분에 입력 https://www.tutorialspoint.com/wcf/wcf_creating_service.htm, 하지만 그다지 도움이되지 못했습니다. 저는 거의 그 튜토리얼에있는 것과 똑같은 일을했습니다. – gqmartins

답변

0

메타 데이터가 노출되었지만 서비스에 바인딩하지 않았습니다. 어떻게해야할까요?

<behaviors> 
      <serviceBehaviors> 
       <behavior name="metadadiscovery"> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 

이제는 비헤이비어를 서비스에 바인딩하십시오.

<services> 
     <service name="TaskExecutor.Exec" behaviorConfiguration="metadadiscovery"> 
      <endpoint address="" binding="basicHttpBinding" contract="TaskExecutor.IExec"> 
      <identity> 
         <dns value="localhost" /> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
       <host> 
        <baseAddresses> 
         <add baseAddress="http://localhost:8001/TaskExecutor/Exec/" /> 
        </baseAddresses> 
       </host> 
      </service> 
     </services> 

이제 브라우저에 주소를 입력하면 wsdl을 볼 수 있습니다. http://localhost:8001/TaskExecutor/Exec/

+0

입력 해 주셔서 감사합니다! 그러나 그 여전히 그것을하지 않습니다, 나는 당신의 대답을 사용하여 같은 오류가 계속 나타납니다 – gqmartins

+0

wsdl을 탐색 할 수 있습니까? –

+0

아니요, wsdl을 기본 URI 앞에 넣거나 기본 URI를 사용하더라도 여전히 오류가 발생합니다. 당신의 컴퓨터에서 작동하도록 관리합니까? – gqmartins

0

그래서 나는 무엇이 잘못되었는지 알아 냈습니다. 서비스를 시작한 코드였습니다. 대신 내가 가진 무엇은해야한다 :

using (ServiceHost host = new ServiceHost(typeof(Exec))) 
{ 
    host.Open(); 
    Console.WriteLine("exec service started at {0}", host.BaseAddresses[0]); 
    Console.WriteLine("Press any key to end..."); 
    Console.ReadLine(); 
}