WebServicePlugin.cs
6.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//*************************************************************************************************
// WebServicePlugin.cs
// Owner: Mahipal Kante
//
// This Web Test plugin performs Data Binding on binary format for Web Service response
// When the Web Service response is 'application/soap+msbin1'
// (binary - used by Silverlight application with WCF RIA)
//
// Copyright(c) Microsoft Corporation, 2010
//*************************************************************************************************
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Diagnostics.CodeAnalysis;
namespace WebTest.WebService.Plugin.Runtime
{
public class WebServicePlugin : WebTestPlugin
{
/// Summary:
/// When overridden in a derived class, represents the method that will handle
/// the event associated with the completion of a Web page.
///
/// Parameters:
/// sender:
/// The source of the event.
///
/// e:
/// A PostPageEventArgs that contains the event data.
///
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PostPage(object sender, PostPageEventArgs e)
{
}
//
// Summary:
// When overridden in a derived class, represents the method that will handle
// the event associated with the completion of an HTTP request.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A PostRequestEventArgs that contains the event data.
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PostRequest(object sender, PostRequestEventArgs e)
{
}
//
// Summary:
// When overridden in a derived class, represents the method that will handle
// the event associated with the completion of a transaction that is defined
// in the Web test.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A PostTransactionEventArgs that contains the event data.
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PostTransaction(object sender, PostTransactionEventArgs e)
{
}
//
// Summary:
// When overridden in a derived class, represents the method that will handle
// the event associated with the end of a Web test.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A Microsoft.VisualStudio.TestTools.WebTesting.PostWebTestEventArgs that contains
// the event data.
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PostWebTest(object sender, PostWebTestEventArgs e)
{
}
//
// Summary:
// When overridden in a derived class, represents the method that will handle
// the event associated with the start of a Web page.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A PrePageEventArgs that contains the event data.
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PrePage(object sender, PrePageEventArgs e)
{
}
//
// Summary:
// When overridden in a derived class, represents the method that will handle
// the event associated with the start of an HTTP request.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A PreRequestEventArgs that contains the event data.
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PreRequest(object sender, PreRequestEventArgs e)
{
}
/// <summary>
/// This method performs Data Binding on MSBin1 binray format for Web Service response
/// When the Web Service response is 'application/soap+msbin1'
// (binary - used by Silverlight application with WCF RIA)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PreRequestDataBinding(object sender, PreRequestDataBindingEventArgs e)
{
BinaryHttpBody binaryHttpBody = e.Request.Body as BinaryHttpBody;
if (binaryHttpBody == null || string.IsNullOrEmpty(binaryHttpBody.ContentType))
{
return;
}
if (!binaryHttpBody.ContentType.Contains("msbin1"))
{
return;
}
ContentHandler contentHandler = ContentHandlerFactory.GetHandler(binaryHttpBody.ContentType);
if (contentHandler != null)
{
contentHandler.MessageBytes = binaryHttpBody.Data;
string text = contentHandler.MessageString;
// do Data Binding on the string version of binary data
string newText = DataBindingHelper.UpdateBindingSites(e.WebTest.Context, text);
contentHandler.MessageString = newText;
// set the new binary data into http body
binaryHttpBody.Data = contentHandler.MessageBytes;
}
}
//
// Summary:
// When overridden in a derived class, represents the method that will handle
// the event associated with the start of a transaction that is defined in the
// Web test.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A PreTransactionEventArgs that contains the event data.
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PreTransaction(object sender, PreTransactionEventArgs e)
{
}
//
// Summary:
// When overridden in a derived class, represents the method that will handle
// the event associated with the start of a Web test.
//
// Parameters:
// sender:
// The source of the event.
//
// e:
// A Microsoft.VisualStudio.TestTools.WebTesting.PostWebTestEventArgs that contains
// the event data.
[SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
}
}
}