다음을 통해 공유


방법: 구독에서 웹 동기화를 사용하도록 구성(RMO 프로그래밍)

이 항목의 절차는 병합 복제를 위해 웹 동기화를 구성하는 세 번째 단계입니다. 게시를 설정하고 Microsoft 인터넷 정보 서비스(IIS)를 실행하는 컴퓨터를 구성한 다음 이 단계를 수행합니다. 구성 프로세스에 대한 개요는 방법: 병합 복제에 대한 웹 동기화 구성(RMO 프로그래밍)을 참조하십시오. HTTP를 통해서만 게시자에 연결할 수 있는 구독자에 대해 웹 동기화를 사용하도록 구독을 구성하는 경우 게시를 올바르게 구성해야 합니다. 자세한 내용은 방법: 웹 동기화를 허용하도록 게시 구성(RMO 프로그래밍)을 참조하십시오. 이 항목의 절차를 완료한 다음에는 만든 구독을 동기화합니다. 자세한 내용은 방법: 끌어오기 구독 동기화(RMO Programming)를 참조하십시오.

이 항목에서는 웹 동기화에 필요한 매개 변수에 대해 설명합니다. 끌어오기 구독을 만드는 방법은 방법: 끌어오기 구독 만들기(RMO Programming)를 참조하십시오.

중요 정보중요

웹 동기화에 사용되는 웹 서버의 URL(예: https://server.domain.com/directory/replisapi.dll)은 replisapi.dll의 위치를 지정합니다. 서버가 SSL(Secure Sockets Layer)에 대해 기본 포트 443 외의 다른 포트를 사용하도록 구성된 경우 https://server.domain.com:PortNumber/directory/replisapi.dll과 같이 해당 포트도 지정해야 합니다. URL의 서버 이름은 인증서를 만들 때 사용된 서버 이름과 동일해야 합니다. 예를 들어 인트라넷에서는 https://server/를 통해 웹 서버에 액세스할 수 있습니다. 그러나 인증서를 만들 때 https://server.domain.com/과 같은 정규화된 이름을 사용한 경우에는 https://server.domain.com/directory/replisapi.dll과 같이 URL에 이 정규화된 이름을 사용해야 합니다.

구독에서 웹 동기화를 사용하도록 구성하려면

  1. ServerConnection 클래스를 사용하여 구독자 및 게시자에 대한 연결을 만듭니다.

  2. 1단계에서 만든 게시자 연결을 사용하여 MergePublication 클래스의 인스턴스를 만듭니다.

  3. (옵션) 구독 데이터베이스가 없으면 SQL SMO(Server Management Objects) Database 클래스를 사용하여 만듭니다. 자세한 내용은 데이터베이스 생성, 변경 및 제거를 참조하십시오.

  4. MergePullSubscription 클래스의 인스턴스를 만듭니다.

  5. 다음 구독 속성을 설정합니다.

  6. Create 메서드를 호출합니다.

  7. 2단계에서 만든 MergePublication 인스턴스를 사용하여 MakePullSubscriptionWellKnown 메서드를 호출하고 끌어오기 구독을 게시자에 등록합니다.

HTTP를 사용하는 웹 서버를 통해서만 게시자에 연결할 수 있는 구독자에 대해 웹 동기화를 사용하도록 구독을 구성하려면

  1. ServerConnection 클래스를 사용하여 구독자 연결을 만듭니다.

  2. (옵션) 구독 데이터베이스가 없는 경우 SMO Database 클래스를 사용하여 만듭니다. 자세한 내용은 데이터베이스 생성, 변경 및 제거를 참조하십시오.

  3. MergePullSubscription 클래스의 인스턴스를 만듭니다.

  4. 다음 구독 속성을 설정합니다.

  5. Create 메서드를 호출합니다.

다음 예에서는 웹 동기화를 사용하여 게시자와 동기화되는 구독을 만듭니다.

           // Define the Publisher, publication, and databases.
            string publicationName = "AdvWorksSalesOrdersMerge";
            string publisherName = publisherInstance;
            string subscriberName = subscriberInstance;
            string subscriptionDbName = "AdventureWorks2008R2Replica";
            string publicationDbName = "AdventureWorks2008R2";
            string hostname = @"adventure-works\garrett1";
            string webSyncUrl = "https://" + publisherInstance + "/WebSync/replisapi.dll";

            //Create connections to the Publisher and Subscriber.
            ServerConnection subscriberConn = new ServerConnection(subscriberName);
            ServerConnection publisherConn = new ServerConnection(publisherName);

            // Create the objects that we need.
            MergePublication publication;
            MergePullSubscription subscription;

            try
            {
                // Connect to the Subscriber.
                subscriberConn.Connect();

                // Ensure that the publication exists and that 
                // it supports pull subscriptions and Web synchronization.
                publication = new MergePublication();
                publication.Name = publicationName;
                publication.DatabaseName = publicationDbName;
                publication.ConnectionContext = publisherConn;

                if (publication.LoadProperties())
                {
                    if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
                    {
                        publication.Attributes |= PublicationAttributes.AllowPull;
                    }
                    if ((publication.Attributes & PublicationAttributes.AllowWebSynchronization) == 0)
                    {
                        publication.Attributes |= PublicationAttributes.AllowWebSynchronization;
                    }

                    // Define the pull subscription.
                    subscription = new MergePullSubscription();
                    subscription.ConnectionContext = subscriberConn;
                    subscription.PublisherName = publisherName;
                    subscription.PublicationName = publicationName;
                    subscription.PublicationDBName = publicationDbName;
                    subscription.DatabaseName = subscriptionDbName;
                    subscription.HostName = hostname;

                    // Specify the Windows login credentials for the Merge Agent job.
                    subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
                    subscription.SynchronizationAgentProcessSecurity.Password = winPassword;

                    // Enable Web synchronization.
                    subscription.UseWebSynchronization = true;
                    subscription.InternetUrl = webSyncUrl;

                    // Specify the same Windows credentials to use when connecting to the
                    // Web server using HTTPS Basic Authentication.
                    subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication;
                    subscription.InternetLogin = winLogin;
                    subscription.InternetPassword = winPassword;

                    // Ensure that we create a job for this subscription.
                    subscription.CreateSyncAgentByDefault = true;

                    // Create the pull subscription at the Subscriber.
                    subscription.Create();

                    Boolean registered = false;

                    // Verify that the subscription is not already registered.
                    foreach (MergeSubscription existing
                        in publication.EnumSubscriptions())
                    {
                        if (existing.SubscriberName == subscriberName
                            && existing.SubscriptionDBName == subscriptionDbName
                            && existing.SubscriptionType == SubscriptionOption.Pull)
                        {
                            registered = true;
                        }
                    }
                    if (!registered)
                    {
                        // Register the local subscription with the Publisher.
                        publication.MakePullSubscriptionWellKnown(
                            subscriberName, subscriptionDbName,
                            SubscriptionSyncType.Automatic,
                            MergeSubscriberType.Local, 0);
                    }
                }
                else
                {
                    // Do something here if the publication does not exist.
                    throw new ApplicationException(String.Format(
                        "The publication '{0}' does not exist on {1}.",
                        publicationName, publisherName));
                }
            }
            catch (Exception ex)
            {
                // Implement the appropriate error handling here.
                throw new ApplicationException(String.Format(
                    "The subscription to {0} could not be created.", publicationName), ex);
            }
            finally
            {
                subscriberConn.Disconnect();
                publisherConn.Disconnect();
            }
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2008R2Replica"
Dim publicationDbName As String = "AdventureWorks2008R2"
Dim hostname As String = "adventure-works\garrett1"
Dim webSyncUrl As String = "https://" + publisherInstance + "/WebSync/replisapi.dll"

'Create connections to the Publisher and Subscriber.
Dim subscriberConn As ServerConnection = New ServerConnection(subscriberName)
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)

' Create the objects that we need.
Dim publication As MergePublication
Dim subscription As MergePullSubscription

Try
    ' Connect to the Subscriber.
    subscriberConn.Connect()

    ' Ensure that the publication exists and that 
    ' it supports pull subscriptions and Web synchronization.
    publication = New MergePublication()
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName
    publication.ConnectionContext = publisherConn

    If publication.LoadProperties() Then
        If (publication.Attributes And PublicationAttributes.AllowPull) = 0 Then
            publication.Attributes = publication.Attributes _
            Or PublicationAttributes.AllowPull
        End If
        If (publication.Attributes And PublicationAttributes.AllowWebSynchronization) = 0 Then
            publication.Attributes = publication.Attributes _
            Or PublicationAttributes.AllowWebSynchronization
        End If

        ' Define the pull subscription.
        subscription = New MergePullSubscription()
        subscription.ConnectionContext = subscriberConn
        subscription.PublisherName = publisherName
        subscription.PublicationName = publicationName
        subscription.PublicationDBName = publicationDbName
        subscription.DatabaseName = subscriptionDbName
        subscription.HostName = hostname
        subscription.CreateSyncAgentByDefault = True

        ' Specify the Windows login credentials for the Merge Agent job.
        subscription.SynchronizationAgentProcessSecurity.Login = winLogin
        subscription.SynchronizationAgentProcessSecurity.Password = winPassword

        ' Enable Web synchronization.
        subscription.UseWebSynchronization = True
        subscription.InternetUrl = webSyncUrl

        ' Specify the same Windows credentials to use when connecting to the
        ' Web server using HTTPS Basic Authentication.
        subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication
        subscription.InternetLogin = winLogin
        subscription.InternetPassword = winPassword

        ' Create the pull subscription at the Subscriber.
        subscription.Create()

        Dim registered As Boolean = False

        ' Verify that the subscription is not already registered.
        For Each existing As MergeSubscription In _
        publication.EnumSubscriptions()
            If existing.SubscriberName = subscriberName Then
                registered = True
            End If
        Next
        If Not registered Then
            ' Register the local subscription with the Publisher.
            publication.MakePullSubscriptionWellKnown( _
             subscriberName, subscriptionDbName, _
             SubscriptionSyncType.Automatic, _
             MergeSubscriberType.Local, 0)
        End If
    Else
        ' Do something here if the publication does not exist.
        Throw New ApplicationException(String.Format( _
         "The publication '{0}' does not exist on {1}.", _
         publicationName, publisherName))
    End If
Catch ex As Exception
    ' Implement the appropriate error handling here.
    Throw New ApplicationException(String.Format( _
     "The subscription to {0} could not be created.", publicationName), ex)
Finally
    subscriberConn.Disconnect()
    publisherConn.Disconnect()
End Try

다음 예에서는 HTTP를 사용하는 웹 서버를 통해서만 게시자에 연결할 수 있는 구독자에 대해 웹 동기화를 사용하여 게시자와 동기화되는 구독을 만듭니다.

// The publication must support anonymous Subscribers, pull 
// subscriptions, and Web synchronization.
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2008R2Replica";
string publicationDbName = "AdventureWorks2008R2";
string hostname = @"adventure-works\garrett1";
string webSyncUrl = "https://" + publisherInstance + "/WebSync/replisapi.dll";

//Create the Subscriber connection.
ServerConnection conn = new ServerConnection(subscriberName);

// Create the objects that we need.
MergePullSubscription subscription;

try
{
    // Connect to the Subscriber.
    conn.Connect();

    // Define the pull subscription.
    subscription = new MergePullSubscription();
    subscription.ConnectionContext = conn;
    subscription.PublisherName = publisherName;
    subscription.PublicationName = publicationName;
    subscription.PublicationDBName = publicationDbName;
    subscription.DatabaseName = subscriptionDbName;
    subscription.HostName = hostname;

    // Specify an anonymous Subscriber type since we can't 
    // register at the Publisher with a direct connection.
    subscription.SubscriberType = MergeSubscriberType.Anonymous;

    // Specify the Windows login credentials for the Merge Agent job.
    subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
    subscription.SynchronizationAgentProcessSecurity.Password = winPassword;

    // Enable Web synchronization.
    subscription.UseWebSynchronization = true;
    subscription.InternetUrl = webSyncUrl;

    // Specify the same Windows credentials to use when connecting to the
    // Web server using HTTPS Basic Authentication.
    subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication;
    subscription.InternetLogin = winLogin;
    subscription.InternetPassword = winPassword;

    // Ensure that we create a job for this subscription.
    subscription.CreateSyncAgentByDefault = true;

    // Create the pull subscription at the Subscriber.
    subscription.Create();
}
catch (Exception ex)
{
    // Implement the appropriate error handling here.
    throw new ApplicationException(String.Format(
        "The subscription to {0} could not be created.", publicationName), ex);
}
finally
{
    conn.Disconnect();
}
' The publication must support anonymous Subscribers, pull 
' subscriptions, and Web synchronization.
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2008R2Replica"
Dim publicationDbName As String = "AdventureWorks2008R2"
Dim hostname As String = "adventure-works\\garrett1"
Dim webSyncUrl As String = "https://" + publisherInstance + "/WebSync/replisapi.dll"

'Create the Subscriber connection.
Dim conn As ServerConnection = New ServerConnection(subscriberName)

' Create the objects that we need.
Dim subscription As MergePullSubscription

Try
    ' Connect to the Subscriber.
    conn.Connect()

    ' Define the pull subscription.
    subscription = New MergePullSubscription()
    subscription.ConnectionContext = conn
    subscription.PublisherName = publisherName
    subscription.PublicationName = publicationName
    subscription.PublicationDBName = publicationDbName
    subscription.DatabaseName = subscriptionDbName
    subscription.HostName = hostname

    ' Specify an anonymous Subscriber type since we can't 
    ' register at the Publisher with a direct connection.
    subscription.SubscriberType = MergeSubscriberType.Anonymous

    ' Specify the Windows login credentials for the Merge Agent job.
    subscription.SynchronizationAgentProcessSecurity.Login = winLogin
    subscription.SynchronizationAgentProcessSecurity.Password = winPassword

    ' Enable Web synchronization.
    subscription.UseWebSynchronization = True
    subscription.InternetUrl = webSyncUrl

    ' Specify the same Windows credentials to use when connecting to the
    ' Web server using HTTPS Basic Authentication.
    subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication
    subscription.InternetLogin = winLogin
    subscription.InternetPassword = winPassword

    ' Ensure that we create a job for this subscription.
    subscription.CreateSyncAgentByDefault = True

    ' Create the pull subscription at the Subscriber.
    subscription.Create()
Catch ex As Exception
    ' Implement the appropriate error handling here.
    Throw New ApplicationException(String.Format( _
         "The subscription to {0} could not be created.", publicationName), ex)
Finally
    conn.Disconnect()
End Try