다음을 통해 공유


보안이 설정되지 않은 인터넷 클라이언트 및 서비스

다음 그림에서는 보안이 설정되지 않은 공용 WCF(Windows Communication Foundation) 클라이언트 및 서비스를 보여 줍니다.

보안이 설정되지 않은 인터넷 클라이언트 및 서비스 시나리오

Characteristic 설명

보안 모드

없음

전송

HTTP

바인딩

코드에서는 BasicHttpBinding, 구성에서는 <basicHttpBinding> 요소

상호 운용성

기존 웹 서비스 클라이언트 및 서비스와의 상호 운용성

인증

없음

무결성

없음

기밀성

없음

서비스

다음 코드와 구성은 독립적으로 실행되어야 합니다. 다음 작업 중 하나를 수행합니다.

  • 구성 없이 코드를 사용하여 독립 실행형 서비스를 만듭니다.

  • 제공된 구성을 사용하여 서비스를 만들지만 끝점을 정의하지 않습니다.

코드

다음 코드에서는 보안 없이 끝점을 만드는 방법을 보여 줍니다. 기본적으로 BasicHttpBinding에는 None으로 설정된 보안 모드가 있습니다.

Dim httpUri As New Uri("https://localhost/Calculator")

' Create the ServiceHost.
Dim myServiceHost As New ServiceHost(GetType(Calculator), httpUri)

' Create a binding that uses HTTP. By default, 
' this binding has no security.
Dim b As New BasicHttpBinding()

' Add an endpoint to the service.
myServiceHost.AddServiceEndpoint(GetType(ICalculator), b, "")
' Open the service and wait for calls.
AddMexEndpoint(myServiceHost)
myServiceHost.Open()
Console.Write("Listening....")
Console.ReadLine()
' Close the service when a key is pressed.
myServiceHost.Close()
Uri httpUri = new Uri("https://localhost/Calculator");

// Create the ServiceHost.
ServiceHost myServiceHost = new ServiceHost(typeof(Calculator), httpUri);

// Create a binding that uses HTTP. By default, 
// this binding has no security.
BasicHttpBinding b = new BasicHttpBinding();

// Add an endpoint to the service.
myServiceHost.AddServiceEndpoint(typeof(ICalculator), b, "");
// Open the service and wait for calls.
AddMexEndpoint(ref myServiceHost);
myServiceHost.Open();
Console.Write("Listening....");
Console.ReadLine();
// Close the service when a key is pressed.
myServiceHost.Close();

서비스 구성

다음 코드에서는 구성을 사용하여 동일한 끝점을 설정합니다.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors />
    <services>
      <service behaviorConfiguration="" name="ServiceModel.Calculator">
        <endpoint address="https://localhost/Calculator" 
                  binding="basicHttpBinding"
                  bindingConfiguration="Basic_Unsecured" 
                  name="BasicHttp_ICalculator"
                  contract="ServiceModel.ICalculator" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="Basic_Unsecured" />
      </basicHttpBinding>
    </bindings>
    <client />
  </system.serviceModel>
</configuration>

클라이언트

다음 코드와 구성은 독립적으로 실행되어야 합니다. 다음 작업 중 하나를 수행합니다.

  • 이 코드와 클라이언트 코드를 사용하여 독립 실행형 클라이언트를 만듭니다.

  • 끝점 주소를 정의하지 않는 클라이언트를 만듭니다. 대신 구성 이름을 인수로 사용하는 클라이언트 생성자를 사용합니다. 예를 들면 다음과 같습니다.

    Dim cc As New CalculatorClient("EndpointConfigurationName")
    
    CalculatorClient cc = new CalculatorClient("EndpointConfigurationName");
    

코드

다음 코드에서는 보안이 설정되지 않은 끝점에 액세스하는 기본 WCF 클라이언트를 보여 줍니다.

' Create an instance of the BasicHttpBinding. 
' By default, there is no security.
Dim myBinding As New BasicHttpBinding()

' Create the address string, or get it from configuration.
Dim httpUri As String = "https://localhost/Calculator"

' Create an endpoint address with the address.
Dim myEndpoint As New EndpointAddress(httpUri)

' Create an instance of the WCF client. The client
' code was generated using the Svcutil.exe tool.
Dim cc As New CalculatorClient(myBinding, myEndpoint)
Try
    cc.Open()
    ' Begin using the calculator.
    Console.WriteLine(cc.Divide(100, 2))
    
    ' Close the client.
    cc.Close()
Catch tex As TimeoutException
    Console.WriteLine(tex.Message)
    cc.Abort()
Catch cex As CommunicationException
    Console.WriteLine(cex.Message)
    cc.Abort()
Finally
    Console.WriteLine("Closed the client")
    Console.ReadLine()
End Try
// Create an instance of the BasicHttpBinding. 
// By default, there is no security.
BasicHttpBinding myBinding = new BasicHttpBinding();

// Create the address string, or get it from configuration.
string httpUri = "https://localhost/Calculator";

// Create an endpoint address with the address.
EndpointAddress myEndpoint = new EndpointAddress(httpUri);

// Create an instance of the WCF client. The client
// code was generated using the Svcutil.exe tool.
CalculatorClient cc = new CalculatorClient(myBinding, myEndpoint);
try
{
    cc.Open();
    // Begin using the calculator.
    Console.WriteLine(cc.Divide(100, 2));

    // Close the client.
    cc.Close();
}
catch (TimeoutException tex)
{
    Console.WriteLine(tex.Message);
    cc.Abort();
}
catch (CommunicationException cex)
{
    Console.WriteLine(cex.Message);
    cc.Abort();
}
finally
{
    Console.WriteLine("Closed the client");
    Console.ReadLine();
}

클라이언트 구성

다음 코드에서는 클라이언트를 구성합니다.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ICalculator" >
          <security mode="None">
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://localhost/Calculator/Unsecured"
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding_ICalculator"
          contract="ICalculator" 
          name="BasicHttpBinding_ICalculator" />
    </client>
  </system.serviceModel>
</configuration>

참고 항목

개념

보안 개요

기타 리소스

일반적인 보안 시나리오
Windows Server AppFabric 보안 모델