summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-10-04 22:59:14 -0700
committerAndrew <andrewarnott@gmail.com>2008-10-04 22:59:14 -0700
commit3278e2098c375383ca9a1dd06f7340bd69cc1e60 (patch)
tree7c463d7c3b926e09212d73d1e1913723447303cf
parent01a2ce0ccba9d8ba9d562d10c22253a7336ccffd (diff)
downloadDotNetOpenAuth-3278e2098c375383ca9a1dd06f7340bd69cc1e60.zip
DotNetOpenAuth-3278e2098c375383ca9a1dd06f7340bd69cc1e60.tar.gz
DotNetOpenAuth-3278e2098c375383ca9a1dd06f7340bd69cc1e60.tar.bz2
Refactored sample WCF consumer to allow easier calling.
-rw-r--r--samples/Consumer/SampleWcf.aspx.cs17
1 files changed, 11 insertions, 6 deletions
diff --git a/samples/Consumer/SampleWcf.aspx.cs b/samples/Consumer/SampleWcf.aspx.cs
index 4f7730f..a6cdc8f 100644
--- a/samples/Consumer/SampleWcf.aspx.cs
+++ b/samples/Consumer/SampleWcf.aspx.cs
@@ -29,6 +29,16 @@ public partial class SampleWcf : System.Web.UI.Page {
}
protected void getNameButton_Click(object sender, EventArgs e) {
+ string name = CallService(client => client.GetName());
+ Response.Write(name);
+ }
+
+ protected void getAgeButton_Click(object sender, EventArgs e) {
+ int age = CallService(client => client.GetAge());
+ Response.Write(age);
+ }
+
+ private T CallService<T>(Func<DataApiClient, T> predicate) {
DataApiClient client = new DataApiClient();
var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethod.AuthorizationHeaderRequest | HttpDeliveryMethod.PostRequest);
var accessToken = Session["WcfAccessToken"] as string;
@@ -37,15 +47,10 @@ public partial class SampleWcf : System.Web.UI.Page {
HttpRequestMessageProperty httpDetails = new HttpRequestMessageProperty();
httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization];
- string name;
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) {
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails;
- name = client.GetName();
+ return predicate(client);
}
- Response.Write(name);
- }
-
- protected void getAgeButton_Click(object sender, EventArgs e) {
}
private Consumer CreateConsumer() {