MessageQueryTable<TItem> 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
메시지 쿼리 개체의 컬렉션을 관리합니다.
generic <typename TItem>
public ref class MessageQueryTable : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<System::ServiceModel::Dispatcher::MessageQuery ^, TItem>>, System::Collections::Generic::IDictionary<System::ServiceModel::Dispatcher::MessageQuery ^, TItem>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::ServiceModel::Dispatcher::MessageQuery ^, TItem>>
public class MessageQueryTable<TItem> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.ServiceModel.Dispatcher.MessageQuery,TItem>>, System.Collections.Generic.IDictionary<System.ServiceModel.Dispatcher.MessageQuery,TItem>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.ServiceModel.Dispatcher.MessageQuery,TItem>>
type MessageQueryTable<'Item> = class
interface IDictionary<MessageQuery, 'Item>
interface ICollection<KeyValuePair<MessageQuery, 'Item>>
interface seq<KeyValuePair<MessageQuery, 'Item>>
interface IEnumerable
Public Class MessageQueryTable(Of TItem)
Implements ICollection(Of KeyValuePair(Of MessageQuery, TItem)), IDictionary(Of MessageQuery, TItem), IEnumerable(Of KeyValuePair(Of MessageQuery, TItem))
형식 매개 변수
- TItem
쿼리에서 반환되는 값의 형식입니다.
- 상속
-
MessageQueryTable<TItem>
- 구현
-
ICollection<KeyValuePair<MessageQuery,TItem>> ICollection<KeyValuePair<TKey,TValue>> IDictionary<MessageQuery,TItem> IEnumerable<KeyValuePair<MessageQuery,TItem>> IEnumerable<KeyValuePair<TKey,TValue>> IEnumerable<T> IEnumerable
예제
다음 예제에서는 메시지 및 XPath 메시지 쿼리를 만듭니다. 쿼리는 XPathMessageQueryCollection 개체에 포함된 XPathMessageQuery 개체에 의해 평가됩니다. 각 쿼리의 결과는 XPathResult 클래스의 ResultType 속성을 사용하여 테스트됩니다. 대체 코드의 주석 처리를 제거하여 MessageQueryTable<TItem>사용하여 보여 준 유사한 기능을 확인합니다.
using System;
using System.IO;
using System.Xml;
using System.ServiceModel.Dispatcher;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml.XPath;
namespace MessageQueryExamples
{
class Program
{
static void Main(string[] args)
{
// The XPathMessageQueryCollection inherits from MessageQueryCollection.
XPathMessageQueryCollection queryCollection = MessageHelper.SetupQueryCollection();
// Create a message and a copy of the message. You must create a buffered copy to access the message body.
Message mess = MessageHelper.CreateMessage();
MessageBuffer mb = mess.CreateBufferedCopy(int.MaxValue);
// Evaluate every query in the collection.
foreach (XPathMessageQuery q in queryCollection)
{
// Evaluate the query. Note the result type is an XPathResult.
XPathResult qPathResult = q.Evaluate<XPathResult>(mb);
// Use the XPathResult to determine the result type.
Console.WriteLine("Result type: {0}", qPathResult.ResultType);
// The following code prints the result according to the result type.
if (qPathResult.ResultType == XPathResultType.String)
Console.WriteLine("{0} = {1}", q.Expression, qPathResult.GetResultAsString());
if (qPathResult.ResultType == XPathResultType.NodeSet)
{
// Iterate through the node set.
XPathNodeIterator ns = qPathResult.GetResultAsNodeset();
foreach (XPathNavigator n in ns)
Console.WriteLine("\t{0} = {1}", q.Expression, n.Value);
}
if (qPathResult.ResultType == XPathResultType.Number)
Console.WriteLine("\t{0} = {1}", q.Expression, qPathResult.GetResultAsNumber());
if (qPathResult.ResultType == XPathResultType.Boolean)
Console.WriteLine("\t{0} ={1}", q.Expression, qPathResult.GetResultAsBoolean());
if (qPathResult.ResultType == XPathResultType.Error)
Console.WriteLine("\tError!");
}
Console.WriteLine();
// The alternate code below demonstrates similar funcionality using a MessageQueryTable.
// The difference is the KeyValuePair that requires a key to index each value.
// The code uses the expression as the key, and an arbitrary value for the value.
//MessageQueryTable<string> mq = MessageHelper.SetupTable();
//foreach (KeyValuePair<MessageQuery, string> kv in mq)
//{
// XPathMessageQuery xp = (XPathMessageQuery)kv.Key;
// Console.WriteLine("Value = {0}", kv.Value);
// Console.WriteLine("{0} = {1}", xp.Expression, xp.Evaluate<string>(mb));
//}
Console.ReadLine();
}
}
public class MessageHelper
{
static string messageBody =
"<PurchaseOrder date='today'>" +
"<Number>ABC-2009-XYZ</Number>" +
"<Department>OnlineSales</Department>" +
"<Items>" +
"<Item product='nail' quantity='1'>item1</Item>" +
"<Item product='screw' quantity='2'>item2</Item>" +
"<Item product='brad' quantity='3'>" +
"<SpecialOffer/>" +
"Special item4" +
"</Item>" +
"<Item product='SpecialNails' quantity='9'>item5</Item>" +
"<Item product='SpecialBrads' quantity='11'>" +
"<SpecialOffer/>" +
"Special item6" +
"</Item>" +
"<Item product='hammer' quantity='1'>item7</Item>" +
"<Item product='wrench' quantity='2'>item8</Item>" +
"</Items>" +
"<Comments>" +
"Rush order" +
"</Comments>" +
"</PurchaseOrder>";
public static string xpath = "/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@quantity = 1]";
public static string xpath2 = "/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@product = 'nail']";
public static string xpath3 = "/s12:Envelope/s12:Body/PurchaseOrder/Comments";
public static string xpath4 = "count(/s12:Envelope/s12:Body/PurchaseOrder/Items/Item)";
public static string xpath5 = "substring(string(/s12:Envelope/s12:Body/PurchaseOrder/Number),5,4)";
public static string xpath6 = "/s12:Envelope/s12:Body/PurchaseOrder/Department='OnlineSales'";
public static string xpath7 = "//PurchaseOrder/@date";
public static string xpath8 = "//SpecialOffer/ancestor::Item[@product = 'brad']";
// Invoke the correlation data function.
public static string xpath9 = "sm:correlation-data('CorrelationData1')";
public static string xpath10 = "sm:correlation-data('CorrelationData2')";
public static string xpath11 = "/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@quantity = 2]";
public static Message CreateMessage()
{
StringReader stringReader = new StringReader(messageBody);
XmlTextReader xmlReader = new XmlTextReader(stringReader);
Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "http://purchaseorder", xmlReader);
// Add two correlation properties using lambda expressions. The property names are
// CorrelationData1 and CorrelationData2. The first goes to "value1" and the
// second to "value2". You can use your own property names and values.
CorrelationDataMessageProperty data = new CorrelationDataMessageProperty();
data.Add("CorrelationData1", () => "value1");
data.Add("CorrelationData2", () => "value2");
message.Properties[CorrelationDataMessageProperty.Name] = data;
return message;
}
public static XPathMessageQueryCollection SetupQueryCollection()
{
// Create the query collection and add the XPath queries to it. To create
// the query, you must also use a new XPathMessageContext.
XPathMessageQueryCollection queryCollection = new XPathMessageQueryCollection();
XPathMessageContext context = new XPathMessageContext();
queryCollection.Add(new XPathMessageQuery(xpath, context));
queryCollection.Add(new XPathMessageQuery(xpath2, context));
queryCollection.Add(new XPathMessageQuery(xpath3, context));
queryCollection.Add(new XPathMessageQuery(xpath4, context));
queryCollection.Add(new XPathMessageQuery(xpath5, context));
queryCollection.Add(new XPathMessageQuery(xpath6, context));
queryCollection.Add(new XPathMessageQuery(xpath7, context));
queryCollection.Add(new XPathMessageQuery(xpath8, context));
queryCollection.Add(new XPathMessageQuery(xpath9, context));
queryCollection.Add(new XPathMessageQuery(xpath10, context));
queryCollection.Add(new XPathMessageQuery(xpath11, context));
return queryCollection;
}
public static MessageQueryTable<string> SetupTable()
{
// This is optional code to demonstrate using a MessageQueryTable.
// Compare this to the MessageQueryCollection.
MessageQueryTable<string> table = new MessageQueryTable<string>();
XPathMessageContext context = new XPathMessageContext();
// The code adds a KeyValuePair to the table. Each pair requires
// a query used as the Key, and a value that is paired to the key.
table.Add(new XPathMessageQuery(xpath, context), "value10");
table.Add(new XPathMessageQuery(xpath2, context), "value20");
table.Add(new XPathMessageQuery(xpath3, context), "value30");
table.Add(new XPathMessageQuery(xpath4, context), "value40");
table.Add(new XPathMessageQuery(xpath5, context), "value50");
table.Add(new XPathMessageQuery(xpath6, context), "value60");
table.Add(new XPathMessageQuery(xpath7, context), "value70");
table.Add(new XPathMessageQuery(xpath8, context), "value80");
table.Add(new XPathMessageQuery(xpath9, context), "value90");
table.Add(new XPathMessageQuery(xpath10, context), "value100");
table.Add(new XPathMessageQuery(xpath11, context), "value110");
return table;
}
}
}
Imports System.IO
Imports System.Xml
Imports System.ServiceModel.Dispatcher
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Xml.XPath
Namespace MessageQueryExamples
Public Class Program
Public Shared Sub Main(ByVal args As String())
' The XPathMessageQueryCollection inherits from MessageQueryCollection.
Dim queryCollection As XPathMessageQueryCollection = MessageHelper.SetupQueryCollection()
' Create a message and a copy of the message. You must create a buffered copy to access the message body.
Dim mess As Message = MessageHelper.CreateMessage()
Dim mb As MessageBuffer = mess.CreateBufferedCopy(Integer.MaxValue)
' Evaluate every query in the collection.
Dim q As XPathMessageQuery
For Each q In queryCollection
' Evaluate the query. Note the result type is an XPathResult.
Dim qPathResult As XPathResult = q.Evaluate(Of XPathResult)(mb)
' Use the XPathResult to determine the result type.
Console.WriteLine("Result type: {0}", qPathResult.ResultType)
' The following code prints the result according to the result type.
If qPathResult.ResultType = XPathResultType.String Then
Console.WriteLine("{0} = {1}", q.Expression, qPathResult.GetResultAsString())
End If
If (qPathResult.ResultType = XPathResultType.NodeSet) Then
' Iterate through the node set.
Dim ns As XPathNodeIterator = qPathResult.GetResultAsNodeset()
Dim n As XPathNavigator
For Each n In ns
Console.WriteLine(" {0} = {1}", q.Expression, n.Value)
Next
End If
If qPathResult.ResultType = XPathResultType.Number Then
Console.WriteLine(" {0} = {1}", q.Expression, qPathResult.GetResultAsNumber())
End If
If qPathResult.ResultType = XPathResultType.Boolean Then
Console.WriteLine(" {0} ={1}", q.Expression, qPathResult.GetResultAsBoolean())
End If
If qPathResult.ResultType = XPathResultType.Error Then
Console.WriteLine(" Error!")
End If
Next
Console.WriteLine()
' The alternate code below demonstrates similar funcionality using a MessageQueryTable.
' The difference is the KeyValuePair that requires a key to index each value.
' The code uses the expression as the key, and an arbitrary value for the value.
'Dim mq As MessageQueryTable(Of String) = MessageHelper.SetupTable()
'Dim kv As KeyValuePair(Of MessageQuery, String)
'For Each kv In mq
' '
' Dim xp As XPathMessageQuery = CType(kv.Key, XPathMessageQuery)
' Console.WriteLine("Value = {0}", kv.Value)
' Console.WriteLine("{0} = {1}", xp.Expression, xp.Evaluate(Of String)(mb))
'Next
Console.ReadLine()
End Sub
Private Shared Sub Evaluate(ByVal p1 As Object)
Throw New NotImplementedException
End Sub
End Class
Public Class MessageHelper
Shared messageBody As String = _
"<PurchaseOrder date='today'>" + _
"<Number>ABC-2009-XYZ</Number>" + _
"<Department>OnlineSales</Department>" + _
"<Items>" + _
"<Item product='nail' quantity='1'>item1</Item>" + _
"<Item product='screw' quantity='2'>item2</Item>" + _
"<Item product='brad' quantity='3'>" + _
"<SpecialOffer/>" + _
"Special item4" + _
"</Item>" + _
"<Item product='SpecialNails' quantity='9'>item5</Item>" + _
"<Item product='SpecialBrads' quantity='11'>" + _
"<SpecialOffer/>" + _
"Special item6" + _
"</Item>" + _
"<Item product='hammer' quantity='1'>item7</Item>" + _
"<Item product='wrench' quantity='2'>item8</Item>" + _
"</Items>" + _
"<Comments>" + _
"Rush order" + _
"</Comments>" + _
"</PurchaseOrder>"
Public Shared xpath As String = "/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@quantity = 1]"
Public Shared xpath2 As String = "/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@product = 'nail']"
Public Shared xpath3 As String = "/s12:Envelope/s12:Body/PurchaseOrder/Comments"
Public Shared xpath4 As String = "count(/s12:Envelope/s12:Body/PurchaseOrder/Items/Item)"
Public Shared xpath5 As String = "substring(string(/s12:Envelope/s12:Body/PurchaseOrder/Number),5,4)"
Public Shared xpath6 As String = "/s12:Envelope/s12:Body/PurchaseOrder/Department='OnlineSales'"
Public Shared xpath7 As String = "//PurchaseOrder/@date"
Public Shared xpath8 As String = "//SpecialOffer/ancestor::Item[@product = 'brad']"
' Invoke the correlation data function.
Public Shared xpath9 As String = "sm:correlation-data('CorrelationData1')"
Public Shared xpath10 As String = "sm:correlation-data('CorrelationData2')"
Public Shared xpath11 As String = "/s12:Envelope/s12:Body/PurchaseOrder/Items/Item[@quantity = 2]"
Public Shared Function CreateMessage() As Message
Dim stringReader As New StringReader(messageBody)
Dim xmlReader As New XmlTextReader(stringReader)
Dim message As Message = message.CreateMessage( _
MessageVersion.Soap12WSAddressing10, "http://purchaseorder", xmlReader)
' Add two correlation properties using lambda expressions. The property names are
' CorrelationData1 and CorrelationData2. The first goes to "value1" and the
' second to "value2". You can use your own property names and values.
Dim data As New CorrelationDataMessageProperty()
data.Add("CorrelationData1", Function() "value1")
data.Add("CorrelationData2", Function() "value2")
message.Properties(CorrelationDataMessageProperty.Name) = data
Return message
End Function
Public Shared Function SetupQueryCollection() As XPathMessageQueryCollection
' Create the query collection and add the XPath queries to it. To create
' the query, you must also use a new XPathMessageContext.
Dim queryCollection As New XPathMessageQueryCollection()
Dim context As XPathMessageContext = New XPathMessageContext()
queryCollection.Add(New XPathMessageQuery(xpath, context))
queryCollection.Add(New XPathMessageQuery(xpath2, context))
queryCollection.Add(New XPathMessageQuery(xpath3, context))
queryCollection.Add(New XPathMessageQuery(xpath4, context))
queryCollection.Add(New XPathMessageQuery(xpath5, context))
queryCollection.Add(New XPathMessageQuery(xpath6, context))
queryCollection.Add(New XPathMessageQuery(xpath7, context))
queryCollection.Add(New XPathMessageQuery(xpath8, context))
queryCollection.Add(New XPathMessageQuery(xpath9, context))
queryCollection.Add(New XPathMessageQuery(xpath10, context))
queryCollection.Add(New XPathMessageQuery(xpath11, context))
Return queryCollection
End Function
Public Shared Function SetupTable() As MessageQueryTable(Of String)
' This is optional code to demonstrate using a MessageQueryTable.
' Compare this to the MessageQueryCollection.
Dim table As MessageQueryTable(Of String) = New MessageQueryTable(Of String)()
Dim context As XPathMessageContext = New XPathMessageContext()
' The code adds a KeyValuePair to the table. Each pair requires
' a query used as the Key, and a value that is paired to the key.
table.Add(New XPathMessageQuery(xpath, context), "value10")
table.Add(New XPathMessageQuery(xpath2, context), "value20")
table.Add(New XPathMessageQuery(xpath3, context), "value30")
table.Add(New XPathMessageQuery(xpath4, context), "value40")
table.Add(New XPathMessageQuery(xpath5, context), "value50")
table.Add(New XPathMessageQuery(xpath6, context), "value60")
table.Add(New XPathMessageQuery(xpath7, context), "value70")
table.Add(New XPathMessageQuery(xpath8, context), "value80")
table.Add(New XPathMessageQuery(xpath9, context), "value90")
table.Add(New XPathMessageQuery(xpath10, context), "value100")
table.Add(New XPathMessageQuery(xpath11, context), "value110")
Return table
End Function
End Class
End Namespace
생성자
MessageQueryTable<TItem>() |
MessageQueryTable<TItem> 클래스의 새 인스턴스를 초기화합니다. |
속성
Count |
테이블의 쿼리/데이터 쌍 수를 가져옵니다. |
IsReadOnly |
테이블이 읽기 전용인지 여부를 나타내는 값을 가져옵니다. |
Item[MessageQuery] |
데이터 형식과 연결된 쿼리 개체를 가져오거나 설정합니다. |
Keys |
테이블에 포함된 모든 컬렉션 키의 컬렉션을 반환합니다. |
Values |
테이블에 포함된 결과 값의 컬렉션을 가져옵니다. |
메서드
Add(KeyValuePair<MessageQuery,TItem>) |
키/값 쌍으로 정의된 항목을 추가합니다. |
Add(MessageQuery, TItem) |
키/값 시스템을 사용하여 컬렉션에 항목을 추가합니다. |
Clear() |
컬렉션에서 모든 멤버를 제거합니다. |
Contains(KeyValuePair<MessageQuery,TItem>) |
컬렉션에 키/값 구조체로 형식이 지정된 특정 항목이 포함되어 있는지 여부를 확인합니다. |
ContainsKey(MessageQuery) |
컬렉션에 지정된 키가 있는 요소가 포함되어 있는지 여부를 확인합니다. |
CopyTo(KeyValuePair<MessageQuery,TItem>[], Int32) |
컬렉션의 요소를 지정된 인덱스에서 시작하여 Array복사합니다. |
Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
Evaluate<TResult>(Message) |
메시지에 대해 쿼리를 실행하고 결과 컬렉션을 반환합니다. 본문을 쿼리할 수 없습니다. |
Evaluate<TResult>(MessageBuffer) |
메시지에 대해 쿼리를 실행하고 결과를 반환합니다. |
GetEnumerator() |
컬렉션을 반복하는 열거자를 반환합니다. |
GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
Remove(KeyValuePair<MessageQuery,TItem>) |
컬렉션에서 지정된 개체의 첫 번째 항목을 제거합니다. |
Remove(MessageQuery) |
컬렉션에서 지정된 키와 연결된 항목을 제거합니다. |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
TryGetValue(MessageQuery, TItem) |
일치하는 쿼리가 테이블에 저장되는지 여부를 확인합니다. |
명시적 인터페이스 구현
IEnumerable.GetEnumerator() |
컬렉션을 반복하는 데 사용할 수 있는 열거자를 반환합니다. |
확장 메서드
적용 대상
.NET