WCF 서비스에서 시간 초과 값 늘리기


133

WCF 서비스에서 기본 시간 초과를 1 분보다 크게 늘리려면 어떻게합니까?


확실하지 않지만 암묵적으로 묻고 있다고 생각하는 것은 처리하는 데 1 분 이상 걸리는 모든 호출을 시간 초과하도록 서버 측에서 구성 할 수 있는지 여부입니다. 이것은 가능하지 않다
— gravidThoughts

답변:


196

서버 쪽 또는 클라이언트 쪽을 언급하고 있습니까?

클라이언트 의 경우 바인딩 요소 의 sendTimeout 속성 을 조정하려고합니다 . 서비스 의 경우 바인딩 요소 의 receiveTimeout 속성 을 조정하려고합니다 .

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="longTimeoutBinding"
        receiveTimeout="00:10:00" sendTimeout="00:10:00">
        <security mode="None"/>
      </binding>
    </netTcpBinding>
  </bindings>

  <services>
    <service name="longTimeoutService"
      behaviorConfiguration="longTimeoutBehavior">
      <endpoint address="net.tcp://localhost/longtimeout/"
        binding="netTcpBinding" bindingConfiguration="longTimeoutBinding" />
    </service>
....

물론 원하는 엔드 포인트를 해당 바인딩에 매핑해야합니다.


끝점 태그 안에 'bindingname'을 사용하여 바인딩을 어떻게 매핑합니까?
— Blankman

이것은 단순히 잘못receiveTimeout 세션 기반 바인딩 게으름의 서버 측을 다스리 결정합니다. 예를 들어, 서버는 기본 HTTP 바인딩에이 설정을 사용하지 않습니다. 당신은 WCF에 대한 자신의 서버 측 처리 시간 제한을 롤해야
— gravidThoughts

45

Visual Studio 2008의 도구 메뉴 (또는 올바른 WCF 항목이 설치된 경우 2005)에는 'WCF 서비스 구성 편집기'라는 옵션이 있습니다.

여기에서 클라이언트와 서비스 모두에 대한 바인딩 옵션을 변경할 수 있습니다. 이러한 옵션 중 하나는 시간 종료를위한 것입니다.


이 도구는 요소를 잘못된 방식으로 감싸거나 철자를 쓰는 등의 오류를 피할 수있는 좋은 방법입니다.
— markaaronky

로그 파일을 여는 다른 도구는 여기도 참조하십시오 : stackoverflow.com/a/34283667/187650
— juFo


8

두 가지 방법을 선택할 수 있습니다.

1) 클라이언트의 코드

public static void Main()
{
    Uri baseAddress = new Uri("http://localhost/MyServer/MyService");

    try
    {
        ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));

        WSHttpBinding binding = new WSHttpBinding();
        binding.OpenTimeout = new TimeSpan(0, 10, 0);
        binding.CloseTimeout = new TimeSpan(0, 10, 0);
        binding.SendTimeout = new TimeSpan(0, 10, 0);
        binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

        serviceHost.AddServiceEndpoint("ICalculator", binding, baseAddress);
        serviceHost.Open();

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

    }
    catch (CommunicationException ex)
    {
        // Handle exception ...
    }
}

2) 웹 서버에서 WebConfig로

<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding openTimeout="00:10:00" 
                 closeTimeout="00:10:00" 
                 sendTimeout="00:10:00" 
                 receiveTimeout="00:10:00">
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>

자세한 내용은 공식 문서를 참조하십시오

바인딩에서 시간 초과 값 구성

WSHttpBinding 클래스


0

바인딩 시간 초과 ( Timespans에 있음) 외에도이 시간 이 필요할 수도 있습니다. 몇 초 안에 요

<system.web>
    <httpRuntime executionTimeout="600"/><!-- = 10 minutes -->
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.