IHttpProtocolProvider Interface

HTTP ベースのカスタム配信プロトコルを開発するためのフレームワークです。

名前空間: Microsoft.SqlServer.NotificationServices
アセンブリ: Microsoft.SqlServer.NotificationServices (microsoft.sqlserver.notificationservices.dll 内)

構文

'宣言
Public Interface IHttpProtocolProvider
public interface IHttpProtocolProvider
public interface class IHttpProtocolProvider
public interface IHttpProtocolProvider
public interface IHttpProtocolProvider

解説

このインターフェイスは、HTTP ベースのカスタム配信プロトコルを開発するためのフレームワークです。このインターフェイスは、カスタム開発されることが多い HTTP ベースの配信プロトコルについて、開発の簡素化を支援するために用意されています。HTTP ベースではないカスタム配信プロトコルや、IHttpProtocolProvider よりも高い柔軟性が要求される HTTP ベースの配信プロトコルには、IDeliveryProtocol インターフェイスを使用します。

IHttpProtocolProvider インターフェイスには、次のメソッドが用意されています。

  • Initialize: ディストリビュータで配信プロトコルを初期化できます。

  • FormatEnvelope: ディストリビュータはフォーマットされた通知データを配信プロトコルに渡します。配信プロトコルは、この情報を使用して HTTP エンベロープを作成します。

  • ProcessResponse: 配信プロトコルはサーバーから HTTP 応答を受信し、処理します。

  • Close: 使用中のリソースを解放し、シャットダウンするよう、ディストリビュータから配信プロトコルに指示します。

呼び出しのシーケンスは、Initialize で始まり、次に、送信されるメッセージごとに FormatEnvelopeProcessResponse のペアが 1 組ずつ呼び出されます。Close は、このシーケンスで最後に呼び出されるメソッドです。Close が完了した後、新しい Initialize を使用して一連のメソッド呼び出しをやり直さない限り、FormatEnvelopeProcessResponse が再度呼び出されることはありません。

IHttpProtocolProvider インターフェイスは、Notification Services によって提供される内部 HttpExtension クラスと連動します。このクラスは、要求を発行して HTTP サーバーから応答を受信するなど、HTTP ベースの配信プロトコルの実装時に必要な基本機能のほとんどをラップしています。これにより、開発者は、IHttpProtocolProvider インターフェイスで提供されているメソッドを使用して、メッセージ エンベロープを作成し、HTTP 応答を処理するだけで済みます。

ディストリビュータでは、IHttpProtocolProvider メソッドでのタイムアウトは強制されません。この実装を備えた配信プロトコルのクラスは、信頼関係のある、テスト済みのコードであると見なされます。いずれかのメソッドが応答を停止した場合、そのメソッドを呼び出したディストリビュータ スレッドも応答を停止します。この状態が多数のスレッドで発生した場合、ディストリビュータの処理が中止される可能性があります。

このインターフェイスを実装するカスタム配信プロトコルを作成するには、IHttpProtocolProvider を実装するクラスを作成し、そのクラス内のインターフェイスから継承されるメソッドを作成する必要があります。そして、アプリケーションに適したメソッドの機能をコーディングします。

HTTP を使用してカスタム プロトコルを作成する場合には、不正な送信を防止する対策を講じる必要があります。次に、不正使用を制限するための手法の例を示します。

  • 配信チャネルと受信側エージェントが秘密鍵を共有できる場合には、シークレット キーを使用して SHA1 ハッシュを生成できます。詳細については、「Ensuring Data Integrity with Hash Codesハッシュ コードによるデータの整合性の保証」を参照してください。

  • 匿名の要求を拒否し、Microsoft Windows 認証のみを受け付けるように IIS を構成します。アプリケーションが通知を送信すると、要求側ユーザーの身元を確認してから通知が受信されます。

  • 常に同じコンピュータから送信される場合には、そのコンピュータの IP アドレスから送信された要求のみを受け入れるように IIS を構成します。

カスタム配信プロトコルの作成に関する詳細については、「カスタム配信プロトコルの開発」を参照してください。

使用例

HTTP ベースのカスタム配信プロトコルを起動するには、次のインターフェイス宣言を使用します。

public interface IHttpProtocolProvider
{
    void Initialize(StringDictionary channelArguments);
    String FormatEnvelope(
                StringDictionary protocolFields,
                String requestBody);
    Boolean ProcessResponse(
                HttpStatusCode httpResponseCode,
                String responseBody,
                Boolean postSuccess);
    void Close();
}

次のコード例では、HTTP 配信プロトコルは XSLT ファイルとプロトコル フィールドを組み合わせて使用して、エンベロープを構築しています。

using System;
using System.Collections.Specialized;
using System.Text;
using System.Net;
using System.Xml;
using System.IO;
using Microsoft.SqlServer.NotificationServices;

namespace AdventureWorks.Notifications.HttpDeliveryProtocol
{
    public class SoapProtocol: IHttpProtocolProvider
    {

        public SoapProtocol()
        {
            // Add constructor logic here if required.
        }
        
        // Implement the IHttpProviderProtocol.Initialize method.
        public void Initialize(StringDictionary channelArguments)
        {
            // Process initialization parameters
            // if any are necessary.
        }

        // Implement the IHttpProviderProtocol.FormatEnvelope method.
        public string FormatEnvelope(StringDictionary protocolFields,
            string requestBody)
        {
            // Use a StringBuilder, a StringWriter, and
            // an XmlTextWriter to create the XML string.
            StringBuilder envelopeBuilder = new StringBuilder();
            StringWriter  envelopeWriter =
                new StringWriter(envelopeBuilder);
            XmlTextWriter xmlWriter = new 
                      XmlTextWriter(envelopeWriter);
            // Create the envelope.
            xmlWriter.WriteStartElement("soap:envelope");
            // Create the header.
            xmlWriter.WriteStartElement("soap:header");
            xmlWriter.WriteStartElement("username");
            xmlWriter.WriteString(protocolFields["userName"]);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("password");
            xmlWriter.WriteString(protocolFields["password"]);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();
            // Create the body.
            xmlWriter.WriteStartElement("soap:body");
            xmlWriter.WriteString(requestBody);
            xmlWriter.WriteEndElement();
            // Close the envelope.
            xmlWriter.WriteEndElement();

            string envelope = envelopeBuilder.ToString();

            xmlWriter.Close();

            return envelope;
        }

        // Implement the IHttpProviderProtocol.ProcessResponse method.
        public bool ProcessResponse(HttpStatusCode statusCode,
            string responseBody,
            bool postSuccess)
        {
            if (postSuccess)
            {
                return postSuccess;
            }
            else
            {
                return(false);
                // You could log the responseBody info here.
            }
        }

        // Implement the IHttpProviderProtocol.Close method.
        public void Close()
        {
            // Release any system resources here.
        }
    }
}

プラットフォーム

開発プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

対象プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

参照

関連項目

IHttpProtocolProvider Members
Microsoft.SqlServer.NotificationServices Namespace