2012-01-10 3 views
0

this example을 기반으로 WCF 콜백 서비스에 대한 자체 호스팅을 수행하려고합니다.콜백 WCF 서비스를 만들 때 EndpointNotFoundException이 발생했습니다.

서비스 :

static void Main(string[] args) 
    { 
     using (ServiceHost host = new ServiceHost(typeof(Message), new Uri("http://localhost:8000/HelloWCF"))) 
     { 
      // Set up a service endpoint [Contract, Binding, Address] 
      host.AddServiceEndpoint(typeof(IMessage), new WSDualHttpBinding() { ClientBaseAddress = new Uri("http://locahost:8001/HelloWCF") }, "HelloWCF"); 

      // Enable metadata exchange 
      ServiceMetadataBehavior smb = new ServiceMetadataBehavior() {HttpGetEnabled =true }; 

      host.Description.Behaviors.Add(smb); 
      host.Open(); 

      Console.WriteLine("Ready..."); 
      Console.ReadLine(); 
     } 
    } 

클라이언트 :

의 app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsDualHttpBinding > 
       <binding name="WSDualHttpBinding_IMessage" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" clientBaseAddress="http://locahost:8001/HelloWCF"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" /> 
        <security mode="Message"> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" 
          algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </wsDualHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:8000/HelloWCF/HelloWCF" binding="wsDualHttpBinding" 
       bindingConfiguration="WSDualHttpBinding_IMessage" contract="CallbackService.IMessage" 
       name="WSDualHttpBinding_IMessage" > 
       <identity> 
        <userPrincipalName value="badasscomputing\menkaur" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

C# 코드 :

[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] 
    class Sender : IMessageCallback, IDisposable 
    { 
     private MessageClient messageClient; 

     public void Go() 
     { 
      InstanceContext context = new InstanceContext(this); 
      messageClient = new MessageClient(context, "WSDualHttpBinding_IMessage"); 

      for (int i = 0; i < 5; i++) 
      { 
       string message = string.Format("message #{0}", i); 
       Console.WriteLine(">>> Sending " + message); 
       messageClient.AddMessage(message); 
      } 

     } 

     public void OnMessageAdded(string message, DateTime timestamp) 
     { 
     } 

     public void Dispose() 
     { 
      messageClient.Close(); 
     } 
    } 

    [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] 
    class Listener : IMessageCallback, IDisposable 
    { 
     private MessageClient messageClient; 

     public void Open() 
     { 
      InstanceContext context = new InstanceContext(this); 
      messageClient = new MessageClient(context, "WSDualHttpBinding_IMessage"); 

      messageClient.Subscribe(); 
     } 

     public void OnMessageAdded(string message, DateTime timestamp) 
     { 
      Console.WriteLine("<<< Recieved {0} with a timestamp of {1}", message, timestamp); 
     } 

     public void Dispose() 
     { 
      messageClient.Unsubscribe(); 
      messageClient.Close(); 
     } 
    } 

    static void Main(string[] args) 
    { 
     Listener l = new Listener(); 
     l.Open(); 

     Sender s = new Sender(); 
     s.Go(); 
    } 
여기

는 호스팅 코드입니다

서버가 올바르게 시작됩니다. 클라이언트를 실행할 때 , 그것은 다음과 같은 예외로 서버 함수를 호출 할 때 충돌 :

EndpointNotFoundException:There was no endpoint listening at http://localhost:8000/HelloWCF/HelloWCF that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 

내부 예외는 : 원격 서버에 연결할 수 없습니다.

내가 성공적으로의 원인이 될 수있는 어떤 콜백 함수

없이 유사한 응용 프로그램을 시험이 때문에 방화벽이 아닌?

업데이트]

전체 소스는 여기에서 다운로드 할 수 있습니다 http://iathao.com/tmp/fullSource.zip

+2

* badasscomputing * 내가 http로 클라이언트 측의 엔드 포인트를 설정하면 –

답변

1

이 작은 변경 사항으로 내 컴퓨터에서 코드가 제대로 작동합니다.

클라이언트 설정

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsDualHttpBinding> 
       <binding name="WSDualHttpBinding_IMessage" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" /> 
        <security mode="Message"> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" 
          algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </wsDualHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:8000/HelloWCF" binding="wsDualHttpBinding" 
       bindingConfiguration="WSDualHttpBinding_IMessage" contract="CallbackService.IMessage" 
       name="WSDualHttpBinding_IMessage"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

스타터 코드

또한 내가 컴퓨터/도메인 이름을 좋아
namespace wcfStarter 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      using (ServiceHost host = new ServiceHost(typeof(Message), new Uri("http://localhost:8002/HelloWCF"))) 
      { 
       // Set up a service endpoint [Contract, Binding, Address] 
       host.AddServiceEndpoint(typeof(IMessage), new WSDualHttpBinding() { ClientBaseAddress = new Uri("http://locahost:8001") }, "HelloWCF"); 

       // Enable metadata exchange 
       ServiceMetadataBehavior smb = new ServiceMetadataBehavior() {HttpGetEnabled =true }; 

       host.Description.Behaviors.Add(smb); 
       host.Open(); 

       Console.WriteLine("Ready..."); 
       Console.ReadLine(); 
      } 
     } 
    } 
} 
+0

참조. HTTP http : // + : 80/Temporary_Listen_Addresses/9b0d36c7-c04e-4204-9a7c-eb887b03f3c9 /를 등록 할 수 없습니다. TCP 포트 80을 다른 응용 프로그램에서 사용하고 있기 때문입니다. " –

+0

ClientBaseAddress를 다른 포트로 변경하는 것이 좋습니다. – Jontatas

+1

방금 ​​그 사실을 깨달았습니다. clientBaseAddress = "http : // localhost : 8001"을 configuration/system.serviceModel/bindings/wsDualHttpBinding/binding에 추가하면됩니다. 내 실수는 clientBaseAddress = "http : // locahost : 8001/HelloWCF"로 설정했습니다. –

2

당신은 http://localhost:8000/HelloWCF에서 엔드 포인트를 호스팅 한 것으로 나타났습니다하지만 클라이언트 설정은 http://localhost:8000/HelloWCF/HelloWCF (참고 : 추가 "/ HelloWCF")를 가리키는

UPDATE

클라이언트 설정 계약 CallbackService.IMessage으로 설정되어 있지만 코드에 IMessage 계약의 서비스 구현이 없습니다.

+0

: // localhost를 : 8000/HelloWCF, 내부 예외는 404로 변경되고 서버는 실행 중임 –

+0

내 업데이트 –

+0

을 참조하십시오. IMessage는 서버 측 인터페이스입니다. 클라이언트에서 구현 된 IMessageCallback에 콜백 메시지를 보낼 것을 기대합니다. –

관련 문제