다음을 통해 공유


HttpClientChannel 클래스

정의

HTTP 프로토콜을 사용하여 메시지를 전송하는 원격 호출에 대한 클라이언트 채널을 구현합니다.

public ref class HttpClientChannel : System::Runtime::Remoting::Channels::BaseChannelWithProperties, System::Runtime::Remoting::Channels::IChannelSender
public ref class HttpClientChannel : System::Runtime::Remoting::Channels::BaseChannelWithProperties, System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class HttpClientChannel : System.Runtime.Remoting.Channels.BaseChannelWithProperties, System.Runtime.Remoting.Channels.IChannelSender
public class HttpClientChannel : System.Runtime.Remoting.Channels.BaseChannelWithProperties, System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type HttpClientChannel = class
    inherit BaseChannelWithProperties
    interface IChannelSender
    interface IChannel
type HttpClientChannel = class
    inherit BaseChannelWithProperties
    interface IChannelSender
    interface IChannel
    interface ISecurableChannel
Public Class HttpClientChannel
Inherits BaseChannelWithProperties
Implements IChannelSender
Public Class HttpClientChannel
Inherits BaseChannelWithProperties
Implements IChannelSender, ISecurableChannel
상속
구현

예제

다음 코드 예제에서는 원격 서버 및 해당 클라이언트를 설정 하는 데 사용 HttpClientChannel 하는 방법을 보여 있습니다. 이 예제에는 다음 세 부분이 포함됩니다.

  • 서버

  • 클라이언트

  • 서버 및 클라이언트에서 사용하는 원격 개체

다음 코드 예제에서는 서버를 보여줍니다.

#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;

void main()
{
   // Create the server channel.
   HttpServerChannel^ serverChannel = gcnew HttpServerChannel( 9090 );
   
   // Register the server channel.
   ChannelServices::RegisterChannel( serverChannel );
   
   // Expose an object for remote calls.
   RemotingConfiguration::RegisterWellKnownServiceType( RemoteObject::typeid, L"RemoteObject.rem", WellKnownObjectMode::Singleton );
   
   // Wait for the user prompt.
   Console::WriteLine( L"Press ENTER to exit the server." );
   Console::ReadLine();
   Console::WriteLine( L"The server is exiting." );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class Server
{
    public static void Main(string[] args)
    {
        // Create the server channel.
        HttpServerChannel serverChannel = new HttpServerChannel(9090);

        // Register the server channel.
        ChannelServices.RegisterChannel(serverChannel);

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            WellKnownObjectMode.Singleton);

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
        Console.WriteLine("The server is exiting.");
    }
}

다음 코드 예제에서는 이 서버에 대한 클라이언트를 보여줍니다.

#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;
void main()
{
   // Create the channel.
   HttpClientChannel^ clientChannel = gcnew HttpClientChannel;

   // Register the channel.
   ChannelServices::RegisterChannel( clientChannel );

   // Register as client for remote object.
   WellKnownClientTypeEntry^ remoteType = gcnew WellKnownClientTypeEntry( RemoteObject::typeid,L"http://localhost:9090/RemoteObject.rem" );
   RemotingConfiguration::RegisterWellKnownClientType( remoteType );

   // Create a message sink.
   String^ objectUri;
   System::Runtime::Remoting::Messaging::IMessageSink^ messageSink = clientChannel->CreateMessageSink( L"http://localhost:9090/RemoteObject.rem", nullptr,  objectUri );
   Console::WriteLine( L"The URI of the message sink is {0}.", objectUri );
   if ( messageSink != nullptr )
   {
      Console::WriteLine( L"The type of the message sink is {0}.", messageSink->GetType() );
   }

   // Display the channel's properties using Keys and Item.
   for each(String^ key in clientChannel->Keys)
   {
       Console::WriteLine("clientChannel[{0}] = <{1}>", key, clientChannel[key]);
   }

   // Parse the channel's URI.
   String^ objectUrl = L"http://localhost:9090/RemoteObject.rem";
   String^ channelUri = clientChannel->Parse( objectUrl,  objectUri );
   Console::WriteLine( L"The object URL is {0}.", objectUrl );
   Console::WriteLine( L"The object URI is {0}.", objectUri );
   Console::WriteLine( L"The channel URI is {0}.", channelUri );

   // Create an instance of the remote object.
   RemoteObject^ service = gcnew RemoteObject;
   
   // Invoke a method on the remote object.
   Console::WriteLine( L"The client is invoking the remote object." );
   Console::WriteLine( L"The remote object has been called {0} times.", service->GetCount() );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class Client
{
    public static void Main(string[] args)
    {
        // Create the channel.
        HttpClientChannel clientChannel = new HttpClientChannel();

        // Register the channel.
        ChannelServices.RegisterChannel(clientChannel);

        // Register as client for remote object.
        WellKnownClientTypeEntry remoteType =
            new WellKnownClientTypeEntry(typeof(RemoteObject),
            "http://localhost:9090/RemoteObject.rem");
        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

        // Create a message sink.
        string objectUri;
        System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            clientChannel.CreateMessageSink(
            "http://localhost:9090/RemoteObject.rem",
            null, out objectUri);
        Console.WriteLine(
            "The URI of the message sink is {0}.",
            objectUri);
        if (messageSink != null)
        {
            Console.WriteLine("The type of the message sink is {0}.",
                messageSink.GetType().ToString());
        }

        // Display the channel's properties using Keys and Item.
        foreach(string key in clientChannel.Keys)
        {
            Console.WriteLine(
                "clientChannel[{0}] = <{1}>",
                key, clientChannel[key]);
        }

        // Parse the channel's URI.
        string objectUrl = "http://localhost:9090/RemoteObject.rem";
        string channelUri = clientChannel.Parse(objectUrl, out objectUri);
        Console.WriteLine("The object URL is {0}.", objectUrl);
        Console.WriteLine("The object URI is {0}.", objectUri);
        Console.WriteLine("The channel URI is {0}.", channelUri);

        // Create an instance of the remote object.
        RemoteObject service = new RemoteObject();

        // Invoke a method on the remote object.
        Console.WriteLine("The client is invoking the remote object.");
        Console.WriteLine("The remote object has been called {0} times.",
            service.GetCount());
    }
}

다음 코드 예제에서는 서버 및 클라이언트에서 사용 하는 원격 개체를 보여 있습니다.

#using <System.dll>
using namespace System;
using namespace System::Runtime::Remoting;

// Remote object.
public ref class RemoteObject: public MarshalByRefObject
{
private:
   static int callCount = 0;

public:
   int GetCount()
   {
      Console::WriteLine( L"GetCount was called." );
      callCount++;
      return (callCount);
   }

};
using System;
using System.Runtime.Remoting;

// Remote object.
public class RemoteObject : MarshalByRefObject
{
    private int callCount = 0;

    public int GetCount()
    {
        Console.WriteLine("GetCount was called.");
        callCount++;
        return(callCount);
    }
}

설명

중요합니다

신뢰할 수 없는 데이터를 사용하여 이 클래스에서 메서드를 호출하는 것은 보안 위험입니다. 신뢰할 수 있는 데이터로만 이 클래스의 메서드를 호출합니다. 자세한 내용은 모든 입력 유효성 검사참조하세요.

채널은 원격 경계를 넘어 메시지를 전송합니다(예: 컴퓨터 또는 애플리케이션 도메인 간). 클래스는 HttpClientChannel HTTP 프로토콜을 사용하여 메시지를 전송합니다.

채널은 .NET Framework 원격 인프라에서 원격 호출을 전송하는 데 사용됩니다. 클라이언트가 원격 개체를 호출하면 클라이언트 채널에서 보내고 서버 채널에서 수신하는 메시지로 호출이 직렬화됩니다. 그런 다음 역직렬화되고 처리됩니다. 반환된 값은 서버 채널에서 전송되고 클라이언트 채널에서 수신됩니다.

클라이언트 쪽에서 메시지의 추가 처리를 수행하려면 처리된 모든 메시지가 전달되는 프로세스의 IClientChannelSinkProvider 구현을 HttpClientChannel 지정할 수 있습니다.

기본적으로 HttpServerChannel SOAP 포맷터를 사용하여 모든 메시지를 직렬화합니다.

HttpClientChannel 개체에는 구성 파일(정적 RemotingConfiguration.Configure 메서드를 호출하여) 또는 프로그래밍 방식으로(생성자에 컬렉션을 전달하여) 런타임에 설정할 수 있는 IDictionary 연결된 구성 속성이 HttpClientChannel 있습니다.

생성자

Name Description
HttpClientChannel()

HttpClientChannel 클래스의 새 인스턴스를 초기화합니다.

HttpClientChannel(IDictionary, IClientChannelSinkProvider)

지정된 구성 속성 및 싱크를 HttpClientChannel 사용하여 클래스의 새 인스턴스를 초기화합니다.

HttpClientChannel(String, IClientChannelSinkProvider)

지정된 이름과 싱크를 사용하여 클래스의 HttpClientChannel 새 인스턴스를 초기화합니다.

필드

Name Description
SinksWithProperties

채널 싱크 스택의 위쪽 채널 싱크를 나타냅니다.

(다음에서 상속됨 BaseChannelWithProperties)

속성

Name Description
ChannelName

현재 채널의 이름을 가져옵니다.

ChannelPriority

현재 채널의 우선 순위를 가져옵니다.

Count

채널 개체와 연결된 속성의 수를 가져옵니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
IsFixedSize

채널 개체에 입력할 수 있는 속성 수가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
IsReadOnly

채널 개체의 속성 컬렉션이 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
IsSecured

클라이언트 채널의 보안 여부를 가져오거나 설정합니다.

IsSynchronized

채널 개체 속성의 사전이 동기화되는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
Item[Object]

지정된 채널 속성을 반환합니다.

Keys

ICollection 채널 속성이 연결된 키의 값을 가져옵니다.

Properties

IDictionary 현재 채널 개체와 연결된 채널 속성을 가져옵니다.

(다음에서 상속됨 BaseChannelWithProperties)
SyncRoot

에 대한 액세스를 동기화하는 데 사용되는 개체를 BaseChannelObjectWithProperties가져옵니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
Values

ICollection 채널 개체와 연결된 속성의 값을 가져옵니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)

메서드

Name Description
Add(Object, Object)

NotSupportedException를 throw합니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
Clear()

NotSupportedException를 throw합니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
Contains(Object)

채널 개체에 지정된 키와 연결된 속성이 포함되어 있는지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
CopyTo(Array, Int32)

NotSupportedException를 throw합니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
CreateMessageSink(String, Object, String)

지정된 URL 또는 채널 데이터 개체에 메시지를 전달하는 채널 메시지 싱크를 반환합니다.

Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

IDictionaryEnumerator 채널 개체와 연결된 모든 속성에 대해 열거하는 값을 반환합니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Parse(String, String)

지정된 URL에서 채널 URI 및 잘 알려진 원격 개체 URI를 추출합니다.

Remove(Object)

NotSupportedException를 throw합니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

Name Description
IEnumerable.GetEnumerator()

IEnumerator 채널 개체와 연결된 모든 속성을 열거하는 값을 반환합니다.

(다음에서 상속됨 BaseChannelObjectWithProperties)

확장명 메서드

Name Description
AsParallel(IEnumerable)

쿼리의 병렬 처리를 사용하도록 설정합니다.

AsQueryable(IEnumerable)

IEnumerable IQueryable변환합니다.

Cast<TResult>(IEnumerable)

IEnumerable 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable 요소를 필터링합니다.

적용 대상