2012-03-12 2 views
0

이것은 완전히 단서가없는 문제입니다. 다음과 같이 나는 IWorkerServiceContract 클래스를 정의 :서비스 프록시가 응용 프로그램을 정지시킵니다.

[ServiceContract] 
public interface IWorkerServiceContract 
{ 
    [OperationContract] 
    int Test(int test); 
} 

아무것도 특별한, 난 그냥 연결을 테스트하고 싶었다. 여기 내 서비스 클래스 :

class WorkerService : IWorkerServiceContract 
{ 
    public static ILogger Logger { get; set; } 

    public int Test(int test) 
    { 
     return test + 1; 
    } 

    public static ServiceHost Listen(Uri baseAddress) 
    { 
     ServiceHost host = new ServiceHost(typeof(WorkerService), baseAddress); 

     try 
     { 
      host.Open(); 
      Logger.WriteLine("Listening at address: " + baseAddress.ToString()); 
     } 

     catch (Exception e) 
     { 
      Logger.WriteLine("An exception was thrown, reason: {0}", e.Message); 
     } 

     return host; 
    } 
} 

로거 객체가 초기화 클래스 인스턴스화, 그것은 기본적으로 AllocConsole와 할당 된 콘솔()에 기록합니다. Listen()을 호출하면 모든 것이 잘 작동하며 WCF 테스트 클라이언트를 통해 연결할 수 있고 Test() 메서드를 원격으로 호출 할 수 있습니다. 하지만, 내가 프록시 정의 할 때 :

public partial class WorkerProxy : ClientBase<IWorkerServiceContract>,    
            IWorkerServiceContract 
{ 
    public WorkerProxy(EndpointAddress remoteAddress) : 
     base("workerEndpoint", remoteAddress) 
    { } 

    public WorkerProxy(Uri remoteAddress) : 
     base("workerEndpoint", new EndpointAddress(remoteAddress)) 
    { } 

    public WorkerProxy(string remoteAddress) : 
     base("workerEndpoint", new EndpointAddress(remoteAddress)) 
    { } 

    public int Test(int test) 
    { 
     return base.Channel.Test(test); 
    } 
} 

그리고 다음 코드를 사용합니다

WorkerService.Listen("net.tcp://localhost:19000/dcalc"); 
WorkerProxy wp = new WorkerProxy("net.tcp://localhost:19000/dcalc"); 
wp.Test(0); 

응용 프로그램 정지를! 내가 이해하지 못하는 것은 당신이 볼 수 있듯이, 나는 ManagerService를 정의하고 응용 프로그램이 아무 문제없이 연결할 수 있다는 것입니다

<?xml version="1.0"?> 
<configuration> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding messageEncoding="Mtom" maxReceivedMessageSize="10485760"> 
      <readerQuotas maxArrayLength="10485760" /> 
     </binding> 
     </wsHttpBinding> 
     <netTcpBinding> 
     <binding maxReceivedMessageSize="10485760"> 
      <readerQuotas maxArrayLength="10485760" /> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <services> 
     <service name="DCalc.Manager.ManagerService" behaviorConfiguration="managerServiceBehavior"> 
     <endpoint address="" binding="wsHttpBinding" contract="DCalc.Common.IManagerServiceContract"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
     <service name="DCalc.Worker.WorkerService" behaviorConfiguration="workerServiceBehavior"> 
     <endpoint address="" binding="netTcpBinding" contract="DCalc.Common.IWorkerServiceContract"/> 
     <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <client> 
     <endpoint address="" binding="netTcpBinding" contract="DCalc.Common.IWorkerServiceContract" name="workerEndpoint" /> 
     <endpoint address="" binding="wsHttpBinding" contract="DCalc.Common.IManagerServiceContract" name="managerEndpoint" /> 
    </client> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="managerServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     <behavior name="workerServiceBehavior"> 
      <serviceMetadata policyVersion="Policy15"/> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

: 여기 내 app.config 파일입니다. 그것은 프로토콜 문제가되지 않는 것, 나는 wsHttpBinding과 같은 결과를 얻고있다.

내가 뭘 잘못하고 있니?

답변

2

스레드 교착 상태로 인해 앱을 본 이유는 일부 코드를 실행하거나 공통 리소스에 액세스 할 때 두 개의 스레드가 서로 잠기는 것을 의미합니다. 이 경우

: 작업자 프록시 스레드가 Test(0)를 호출 할 때 클라이언트 측에

, 그것은 돌아올 응답을 기다립니다.

"서버 측"에서 서버 스레드가 동시에 제어를 시도하고 결과를 반환하려고합니다. 두 스레드 간의 스레드 유사성으로 인해 서버 스레드는 작업자 스레드가 완료 될 때까지 대기하지만 작업자 스레드는 응답을 기다리고 있으므로 더 이상 진행할 수 없으며 교착 상태가 발생합니다.

+0

감사합니다. 나는 완전히 그 문제를 간과했습니다! 별도의 스레드에서 실행되는 비동기 프록시를 만들었 기 때문에 ManagerService에 연결할 수있었습니다. – silverhx

관련 문제