다음을 통해 공유


방법: 웹 성능 테스트 편집기에 대한 사용자 지정 HTTP 본문 편집기 만들기

콘텐트는 웹 서비스 요청의 SOAP, 나머지, asmx, wcf, RIA 및 다른 웹 서비스 요청 형식과 문자열 본문 콘텐츠나 이진 본문 또는 편집할 수 있도록 사용자 지정 콘텐츠 편집기를 만들 수 있습니다.

두 가지 유형의 편집기를 구현할 수 있습니다.

이러한 인터페이스는 Microsoft.VisualStudio.TestTools.WebTesting 네임스페이스에 포함되어 있습니다.

요구 사항

  • Visual Studio Ultimate

Windows 컨트롤 라이브러리 프로젝트 만들기

Windows 컨트롤 라이브러리 프로젝트를 사용하여 사용자 정의 컨트롤 만들기

  1. Visual Studio Ultimate에 파일 메뉴를 선택 선택한 다음 프로젝트.

    새 프로젝트 대화 상자가 표시됩니다.

  2. 설치된 템플릿에서 원하는 프로그래밍 언어에 따라 Visual Basic 또는 **Visual C#**을 선택하고 Windows를 선택합니다.

    [!참고]

    이 샘플에서는 Visual C#을 사용합니다.

  3. 템플릿 목록에서 Windows Forms 컨트롤 라이브러리를 선택합니다.

  4. 예를 들어, 이름을 이름 텍스트 상자에를 입력 MessageEditors를 선택 하 고 확인.

    [!참고]

    이 샘플에서는 MessageEditors를 사용합니다.

    프로젝트가 새 솔루션에 추가되고 UserControl1.cs라는 UserControl이 디자이너에 표시됩니다.

  5. 도구 상자공용 컨트롤 범주에서 RichTextBox를 UserControl1로 끌어 옵니다.

  6. 작업 태그 문자 모양을 선택 (스마트 태그 문자 모양)의 오른쪽 위 모서리에 있는 RichTextBox 컨트롤을 선택한 다음 및 부모 컨테이너에서 도킹.

  7. 솔루션 탐색기에서 Windows Forms 라이브러리 프로젝트를 마우스 오른쪽 단추로 클릭하고 속성을 선택합니다.

  8. 속성에서 응용 프로그램 탭을 선택합니다.

  9. 대상 프레임워크 드롭다운 목록에서 .NET Framework 4를 선택합니다.

  10. 대상 프레임워크 변경 대화 상자가 표시됩니다.

  11. 를 선택합니다.

  12. 솔루션 탐색기에서 참조 노드를 마우스 오른쪽 단추로 클릭하고 참조 추가를 선택합니다.

  13. 참조 추가 대화 상자가 표시됩니다.

  14. 선택 된. NET 탭 아래로 스크롤하여 선택 Microsoft.VisualStudio.QualityTools.WebTestFramework 다음 선택 확인.

  15. 디자이너 보기가 아직 열려 있지 않으면 솔루션 탐색기에서 UserControl1.cs를 마우스 오른쪽 단추로 클릭하고 디자이너 보기를 선택합니다.

  16. 디자인 화면에서 마우스 오른쪽 단추를 클릭하고 코드 보기를 선택합니다.

  17. (선택 사항) 클래스 및 생성자의 이름을 UserControl1에서 의미 있는 이름(예: MessageEditorControl)으로 바꿉니다.

    [!참고]

    이 샘플에서는 MessageEditorControl을 사용합니다.

    namespace MessageEditors
    {
        public partial class MessageEditorControl : UserControl
        {
            public MessageEditorControl()
            {
                InitializeComponent();
            }
        }
    }
    
  18. 다음 속성을 추가하여 RichTextBox1의 텍스트를 가져오거나 설정할 수 있도록 합니다.IStringHttpBodyEditorPlugin 인터페이스는 EditString을 사용하고 IBinaryHttpBodyEditorPlugin은 EditByteArray를 사용합니다.

            public String EditString
            {
                get
                {
                    return this.richTextBox1.Text;
                }
                set
                {
                    this.richTextBox1.Text = value;
                }
            }
    
    public byte[] EditByteArray
            {
                get
                {
                    return System.Convert.FromBase64String(richTextBox1.Text);
                }
                set
                {
                    richTextBox1.Text = System.Convert.ToBase64String(value, 0, value.Length);
                }
            }
    

Windows 컨트롤 라이브러리 프로젝트에 클래스 추가

프로젝트에 클래스를 추가합니다.이 클래스는 IStringHttpBodyEditorPluginIBinaryHttpBodyEditorPlugin 인터페이스를 구현하는 데 사용됩니다.

이 절차의 코드 개요

이전 절차에서 만든 MessageEditorControl의 UserControl은 messageEditorControl로 인스턴스화됩니다.

private MessageEditorControl messageEditorControl

messageEditorControl 인스턴스는 CreateEditor 메서드로 만든 플러그 인 대화 상자 내에서 호스팅됩니다.또한 messageEditorControl의 RichTextBoxIHttpBody의 콘텐츠로 채워집니다.그러나 SupportsContentType에서 true를 반환하지 않는 경우에는 플러그 인을 만들 수 없습니다.이 편집기의 경우 IHttpBodyContentType에 "xml"이 포함되어 있으면 SupportsContentType은 true를 반환합니다.

문자열 본문의 편집이 완료된 후 사용자가 플러그 인 대화 상자에서 확인을 클릭하면 편집된 텍스트를 문자열로 가져오고 웹 성능 테스트 편집기의 요청에 있는 문자열 본문을 업데이트하기 위해 GetNewValue가 호출됩니다.

클래스를 만들고 IStringHttpBodyEditorPlugin 인터페이스 코드를 구현하려면

  1. 솔루션 탐색기에서 Windows Forms 컨트롤 라이브러리 프로젝트를 마우스 오른쪽 단추로 클릭하고 새 항목 추가를 선택합니다.

  2. 새 항목 추가 대화 상자가 표시됩니다.

  3. 클래스를 선택합니다.

  4. 이름 텍스트 상자에 클래스의 의미 있는 이름(예: MessageEditorPlugins)을 입력합니다.

  5. 추가를 선택합니다.

    Class1이 프로젝트에 추가되고 코드 편집기에 표시됩니다.

  6. 코드 편집기에서 다음 using 문을 추가합니다.

    using Microsoft.VisualStudio.TestTools.WebTesting;
    
  7. 다음 코드를 작성하거나 복사하여 IStringHttpBodyEditorPlugin 인터페이스의 XmlMessageEditor 클래스를 인스턴스화하고 필요한 메서드를 구현합니다.

        /// <summary>
        /// Editor for generic text based hierarchical messages such as XML and JSON.
        /// </summary>
        public class XmlMessageEditor : IStringHttpBodyEditorPlugin
        {
            public XmlMessageEditor()
            {
            }
    
            /// <summary>
            /// Determine if this plugin supports the content type.
            /// </summary>
            /// <param name="contentType">The content type to test.</param>
            /// <returns>Returns true if the plugin supports the specified content type.</returns>
            public bool SupportsContentType(string contentType)
            {
                return contentType.ToLower().Contains("xml");
            }
    
            /// <summary>
            /// Create a UserControl to edit the specified bytes.  
            /// This control will be hosted in the
            /// plugin dialog which provides OK and Cancel buttons.
            /// </summary>
            /// <param name="contentType">The content type of the BinaryHttpBody.</param>
            /// <param name="initialValue">The bytes to edit.  The bytes are the payload of a BinaryHttpBody.</param>
            /// <returns>A UserControl capable of displaying and editing the byte array value of the specified content type.</returns>
            public object CreateEditor(string contentType, string initialValue)
            {
                messageEditorControl = new MessageEditorControl();
                messageEditorControl.EditString = initialValue;
                return this.messageEditorControl;
            }
    
            /// <summary>
            /// Gets the edited bytes after the OK button is clicked on the plugin dialog.
            /// </summary>
            public string GetNewValue()
            {
                return messageEditorControl.EditString;
            }
    
            private MessageEditorControl messageEditorControl;
        }
    

클래스에 IBinaryHttpBodyEditorPlugin 추가

IBinaryHttpBodyEditorPlugin 인터페이스를 구현합니다.

이 절차의 코드 개요

IBinaryHttpBodyEditorPlugin 인터페이스에 대한 코드 구현은 이전 절차에서 설명한 IStringHttpBodyEditorPlugin과 비슷합니다.그러나 이진 버전에서는 바이트 배열을 사용하여 문자열 대신 이진 데이터를 처리합니다.

첫 번째 절차에서 만든 MessageEditorControl의 UserControl은 messageEditorControl로 인스턴스화됩니다.

private MessageEditorControl messageEditorControl

messageEditorControl 인스턴스는 CreateEditor 메서드로 만든 플러그 인 대화 상자 내에서 호스팅됩니다.또한 messageEditorControl의 RichTextBoxIHttpBody의 콘텐츠로 채워집니다.그러나 SupportsContentType에서 true를 반환하지 않는 경우에는 플러그 인을 만들 수 없습니다.이 편집기의 경우 IHttpBodyContentType에 "msbin1"이 포함되어 있으면 SupportsContentType은 true를 반환합니다.

문자열 본문의 편집이 완료된 후 사용자가 플러그 인 대화 상자에서 확인을 클릭하면 편집된 텍스트를 문자열로 가져오고 웹 성능 테스트 편집기의 요청에 있는 BinaryHttpBody.Data를 업데이트하기 위해 GetNewValue가 호출됩니다.

클래스에 IBinaryHttpBodyEditorPlugin을 추가하려면

  • 이전 절차에서 추가한 XmlMessageEditor 클래스 아래에 다음 코드를 작성하거나 복사하여 IBinaryHttpBodyEditorPlugin 인터페이스의 Msbin1MessageEditor 클래스를 인스턴스화하고 필요한 메서드를 구현합니다.

    /// <summary>
        /// Editor for MSBin1 content type (WCF messages)
        /// </summary>
        public class Msbin1MessageEditor : IBinaryHttpBodyEditorPlugin
        {
            /// <summary>
            /// 
            /// </summary>
            public Msbin1MessageEditor()
            {
            }
    
            /// <summary>
            /// Determine if this plugin supports a content type.
            /// </summary>
            /// <param name="contentType">The content type to test.</param>
            /// <returns>Returns true if the plugin supports the specified content type.</returns>
            public bool SupportsContentType(string contentType)
            {
                return contentType.ToLower().Contains("msbin1");
            }
    
            /// <summary>
            /// Create a UserControl to edit the specified bytes.  This control will be hosted in the
            /// plugin dialog which provides OK and Cancel buttons.
            /// </summary>
            /// <param name="contentType">The content type of the BinaryHttpBody.</param>
            /// <param name="initialValue">The bytes to edit.  The bytes are the payload of a BinaryHttpBody.</param>
            /// <returns>A UserControl capable of displaying and editing the byte array value of the specified content type.</returns>
            public object CreateEditor(string contentType, byte[] initialValue)
            {
                messageEditorControl = new MessageEditorControl();
                messageEditorControl.EditByteArray = initialValue;
                return messageEditorControl;
            }
    
            /// <summary>
            /// Gets the edited bytes after the OK button is clicked on the plugin dialog.
            /// </summary>
            public byte[] GetNewValue()
            {
                return messageEditorControl.EditByteArray;
            }
    
            private MessageEditorControl messageEditorControl;
            private object originalMessage;
        }
    

플러그 인 빌드 및 배포

IStringHttpBodyEditorPlugin 및 IBinaryHttpBodyEditorPlugin의 결과 dll을 빌드하고 배포하려면

  1. 빌드 메뉴에서 빌드 < Windows 폼 컨트롤 라이브러리 프로젝트 이름 >을 선택 합니다.

  2. Visual Studio Ultimate을 종료합니다.

    [!참고]

    dll 파일을 복사하기 전에 Visual Studio Ultimate의 모든 인스턴스를 종료하여 해당 파일이 잠지지 않도록 해야 합니다.

  3. 프로젝트의 bin\debug 폴더에 있는 결과 .dll 파일(예: MessageEditors.dll)을 %ProgramFiles%\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\WebTestPlugins에 복사합니다.

  4. Visual Studio Ultimate를 시작합니다.

    .dll이 Visual Studio Ultimate에 등록됩니다.

웹 성능 테스트를 사용하여 플러그 인 확인

플러그 인을 테스트하려면

  1. 테스트 프로젝트를 만듭니다.

  2. 웹 성능 테스트를 만들고 브라우저에 웹 서비스에 대한 URL(예: http://dev.virtualearth.net/webservices/v1/metadata/searchservice/dev.virtualearth.net.webservices.v1.search.wsdl)을 입력합니다.

  3. 기록을 마치면 웹 성능 테스트 편집기에서 웹 서비스의 요청을 확장하고 문자열 본문 또는 이진 본문을 선택합니다.

  4. 속성 창에서 문자열 본문 또는 이진 본문을 선택 하 고 줄임표 (...)를 선택 합니다.

    HTTP 본문 데이터 편집 대화 상자가 표시됩니다.

  5. 이제 데이터를 편집 하 고 확인을 선택 합니다.그러면 적절한 GetNewValue 메서드가 호출되어 IHttpBody의 콘텐츠가 업데이트됩니다.

코드 컴파일

  • Windows 컨트롤 라이브러리 프로젝트의 대상 프레임 워크가.NET Framework 4.5 인지 확인 합니다.기본적으로 Microsoft.VisualStudio.QualityTools.WebTestFramework 참조를 포함할 수 있는.NET Framework 4.5 클라이언트 프레임 워크 Windows 컨트롤 라이브러리 프로젝트를 대상으로 합니다.

    자세한 내용은 프로젝트 디자이너, 응용 프로그램 페이지(C#)을 참조하십시오.

참고 항목

작업

방법: 요청 수준 플러그 인 만들기

방법: 웹 성능 테스트에 대한 사용자 지정 추출 규칙 만들기

방법: 웹 성능 테스트에 대한 사용자 지정 유효성 검사 규칙 만들기

방법: 부하 테스트 플러그 인 만들기

방법: 코딩된 웹 성능 테스트 만들기

방법: 웹 성능 테스트 결과 뷰어에 대한 Visual Studio 추가 기능 만들기

참조

IStringHttpBodyEditorPlugin

CreateEditor

SupportsContentType

GetNewValue

IBinaryHttpBodyEditorPlugin

CreateEditor

SupportsContentType

GetNewValue

IHttpBody

ContentType

UserControl

RichTextBox

기타 리소스

부하 및 웹 성능 테스트에 대한 사용자 지정 플러그 인 만들기 및 사용