다음을 통해 공유


HttpListener.Start 메서드

정의

이 인스턴스에서 들어오는 요청을 받을 수 있도록 합니다.

public:
 void Start();
public void Start ();
member this.Start : unit -> unit
Public Sub Start ()

예외

Win32 함수 호출이 실패한 경우. 예외의 ErrorCode 속성을 검토하여 예외의 원인을 확인할 수 있습니다.

이 개체가 닫혀 있는 경우

예제

다음 코드 예제에서는 메서드를 Start 사용하여 들어오는 요청 처리를 시작하는 방법을 보여 줍니다.


public static void NonblockingListener(string [] prefixes)
{
    HttpListener listener = new HttpListener();
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback),listener);
    // Applications can do some work here while waiting for the
    // request. If no work can be done until you have processed a request,
    // use a wait handle to prevent this thread from terminating
    // while the asynchronous operation completes.
    Console.WriteLine("Waiting for request to be processed asyncronously.");
    result.AsyncWaitHandle.WaitOne();
    Console.WriteLine("Request processed asyncronously.");
    listener.Close();
}
Public Shared Sub NonblockingListener(ByVal prefixes As String())
    Dim listener As HttpListener = New HttpListener()

    For Each s As String In prefixes
        listener.Prefixes.Add(s)
    Next

    listener.Start()
    Dim result As IAsyncResult = listener.BeginGetContext(New AsyncCallback(AddressOf ListenerCallback), listener)
    ' Applications can do some work here while waiting for the 
    ' request. If no work can be done until you have processed a request,
    ' use a wait handle to prevent this thread from terminating
    ' while the asynchronous operation completes.
    Console.WriteLine("Waiting for request to be processed asyncronously.")
    result.AsyncWaitHandle.WaitOne()
    Console.WriteLine("Request processed asyncronously.")
    listener.Close()
End Sub

설명

또는 BeginGetContext 메서드를 호출하기 전에 이 메서드를 GetContext 호출해야 합니다.

개체를 시작한 후 메서드를 HttpListenerStop 사용하여 중지할 수 있습니다.

참고

이 수신기 instance https를 사용하는 경우 서버 인증서를 설치하고 선택해야 합니다. 그렇지 않으면 연결이 HttpWebRequest 예기치 않게 닫히면 이 HttpListener 쿼리가 실패합니다. HttpCfg.exe 사용하여 서버 인증서 및 기타 수신기 옵션을 구성할 수 있습니다.

호출자 참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

적용 대상