다음을 통해 공유


WS-I Basic Profile 1.1 상호 운용할 수 있는 서비스 만들기

WCF 서비스 끝점을 ASP.NET 웹 서비스 클라이언트와 상호 운용할 수 있도록 구성하려면

  • System.ServiceModel.BasicHttpBinding 형식을 서비스 끝점의 바인딩 형식으로 사용합니다.

  • 서비스 끝점에서 콜백 및 세션 계약 기능이나 트랜잭션 동작을 사용하면 안 됩니다.

바인딩에서 HTTPS 및 전송 수준 클라이언트 인증에 대한 지원을 선택적으로 사용할 수 있습니다.

BasicHttpBinding 클래스의 다음 기능에는 WS-I Basic Profile 1.1 이상의 기능이 필요합니다.

WCF 서비스의 메타데이터를 ASP.NET에서 사용하려면 웹 서비스 클라이언트 생성 도구(Web Services Description Language Tool (Wsdl.exe), Web Services Discovery Tool (Disco.exe)) 및 Visual Studio의 Add Web Reference 기능을 사용합니다. 이때 메타데이터 게시를 활성화해야 합니다. 자세한 내용은 다음 항목을 참조하십시오. 메타데이터 끝점 게시를 참조하십시오.

예제

설명

다음 예제 코드에서는 ASP.NET 웹 서비스 클라이언트와 호환되는 WCF 끝점을 코드 또는 구성 파일에 추가하는 방법에 대해 보여 줍니다.

코드

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.ServiceModel
Imports System.ServiceModel.Description

<ServiceContract()> _
Public Interface IEcho

    <OperationContract()> _
    Function Echo(ByVal s As String) As String

End Interface

Public Class MyService
    Implements IEcho

    Public Function Echo(ByVal s As String) As String Implements IEcho.Echo
        Return s
    End Function

End Class

Friend Class Program

    Shared Sub Main(ByVal args() As String)
        Dim baseAddress = "https://localhost:8080/wcfselfhost/"
        Dim host As New ServiceHost(GetType(MyService), _
                                    New Uri(baseAddress))

        ' Add a service endpoint using the created binding
        With host
            .AddServiceEndpoint(GetType(IEcho), _
                                New BasicHttpBinding(), _
                                "echo1")
            .Open()
            Console.WriteLine("Service listening on {0} . . .", _
                              baseAddress)
            Console.ReadLine()
            .Close()
        End With
    End Sub
End Class
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;

[ServiceContract]
public interface IEcho
{
    [OperationContract]
    string Echo(string s);
}

public class MyService : IEcho
{
    public string Echo(string s)
    {
        return s;
    }
}

class Program
{
    static void Main(string[] args)
    {
        string baseAddress = "https://localhost:8080/wcfselfhost/";
        ServiceHost host = new ServiceHost(typeof(MyService), new Uri(baseAddress));

        // Create a BasicHttpBinding instance
        BasicHttpBinding binding = new BasicHttpBinding();

        // Add a service endpoint using the created binding
        host.AddServiceEndpoint(typeof(IEcho), binding, "echo1");

        host.Open();
        Console.WriteLine("Service listening on {0} . . .", baseAddress);
        Console.ReadLine();
        host.Close();
    }
}
<configuration>
  <system.serviceModel>
    <services>
      <service name="MyService" behaviorConfiguration="HttpGetMetadata">
        <endpoint address="echo2" contract="IEcho" binding="basicHttpBinding" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="HttpGetMetadata">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

참고 항목

개념

ASP.NET 웹 서비스와의 상호 운용성