summaryrefslogtreecommitdiffstats
path: root/samples/Consumer
diff options
context:
space:
mode:
Diffstat (limited to 'samples/Consumer')
-rw-r--r--samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi.wsdl60
-rw-r--r--samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi1.xsd13
-rw-r--r--samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi2.xsd9
-rw-r--r--samples/Consumer/App_WebReferences/SampleServiceProvider/Reference.svcmap1
-rw-r--r--samples/Consumer/SampleWcf.aspx15
-rw-r--r--samples/Consumer/SampleWcf.aspx.cs40
6 files changed, 132 insertions, 6 deletions
diff --git a/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi.wsdl b/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi.wsdl
index 940cb1f..8741a0c 100644
--- a/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi.wsdl
+++ b/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi.wsdl
@@ -182,10 +182,49 @@
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
+ <wsp:Policy wsu:Id="WSHttpBinding_IDataApi_GetFavoriteSites_Input_policy">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Body />
+ <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing" />
+ </sp:SignedParts>
+ <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Body />
+ </sp:EncryptedParts>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
+ <wsp:Policy wsu:Id="WSHttpBinding_IDataApi_GetFavoriteSites_output_policy">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Body />
+ <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing" />
+ <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing" />
+ </sp:SignedParts>
+ <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+ <sp:Body />
+ </sp:EncryptedParts>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:65169/ServiceProvider/DataApi.svc?xsd=xsd0" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="http://localhost:65169/ServiceProvider/DataApi.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
+ <xsd:import schemaLocation="http://localhost:65169/ServiceProvider/DataApi.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="IDataApi_GetAge_InputMessage">
@@ -200,6 +239,12 @@
<wsdl:message name="IDataApi_GetName_OutputMessage">
<wsdl:part name="parameters" element="tns:GetNameResponse" />
</wsdl:message>
+ <wsdl:message name="IDataApi_GetFavoriteSites_InputMessage">
+ <wsdl:part name="parameters" element="tns:GetFavoriteSites" />
+ </wsdl:message>
+ <wsdl:message name="IDataApi_GetFavoriteSites_OutputMessage">
+ <wsdl:part name="parameters" element="tns:GetFavoriteSitesResponse" />
+ </wsdl:message>
<wsdl:portType name="IDataApi">
<wsdl:operation name="GetAge">
<wsdl:input wsaw:Action="http://tempuri.org/IDataApi/GetAge" message="tns:IDataApi_GetAge_InputMessage" />
@@ -209,6 +254,10 @@
<wsdl:input wsaw:Action="http://tempuri.org/IDataApi/GetName" message="tns:IDataApi_GetName_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/IDataApi/GetNameResponse" message="tns:IDataApi_GetName_OutputMessage" />
</wsdl:operation>
+ <wsdl:operation name="GetFavoriteSites">
+ <wsdl:input wsaw:Action="http://tempuri.org/IDataApi/GetFavoriteSites" message="tns:IDataApi_GetFavoriteSites_InputMessage" />
+ <wsdl:output wsaw:Action="http://tempuri.org/IDataApi/GetFavoriteSitesResponse" message="tns:IDataApi_GetFavoriteSites_OutputMessage" />
+ </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WSHttpBinding_IDataApi" type="tns:IDataApi">
<wsp:PolicyReference URI="#WSHttpBinding_IDataApi_policy" />
@@ -235,6 +284,17 @@
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
+ <wsdl:operation name="GetFavoriteSites">
+ <soap12:operation soapAction="http://tempuri.org/IDataApi/GetFavoriteSites" style="document" />
+ <wsdl:input>
+ <wsp:PolicyReference URI="#WSHttpBinding_IDataApi_GetFavoriteSites_Input_policy" />
+ <soap12:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <wsp:PolicyReference URI="#WSHttpBinding_IDataApi_GetFavoriteSites_output_policy" />
+ <soap12:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
</wsdl:binding>
<wsdl:service name="DataApi">
<wsdl:port name="WSHttpBinding_IDataApi" binding="tns:WSHttpBinding_IDataApi">
diff --git a/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi1.xsd b/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi1.xsd
index 3d653c3..531d96b 100644
--- a/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi1.xsd
+++ b/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi1.xsd
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://tempuri.org/" elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:import schemaLocation="http://localhost:65169/ServiceProvider/DataApi.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<xs:element name="GetAge">
<xs:complexType>
<xs:sequence />
@@ -24,4 +25,16 @@
</xs:sequence>
</xs:complexType>
</xs:element>
+ <xs:element name="GetFavoriteSites">
+ <xs:complexType>
+ <xs:sequence />
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="GetFavoriteSitesResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" minOccurs="0" name="GetFavoriteSitesResult" nillable="true" type="q1:ArrayOfstring" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
</xs:schema> \ No newline at end of file
diff --git a/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi2.xsd b/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi2.xsd
new file mode 100644
index 0000000..467098f
--- /dev/null
+++ b/samples/Consumer/App_WebReferences/SampleServiceProvider/DataApi2.xsd
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:complexType name="ArrayOfstring">
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ <xs:element name="ArrayOfstring" nillable="true" type="tns:ArrayOfstring" />
+</xs:schema> \ No newline at end of file
diff --git a/samples/Consumer/App_WebReferences/SampleServiceProvider/Reference.svcmap b/samples/Consumer/App_WebReferences/SampleServiceProvider/Reference.svcmap
index 98b17ca..bf9aa3c 100644
--- a/samples/Consumer/App_WebReferences/SampleServiceProvider/Reference.svcmap
+++ b/samples/Consumer/App_WebReferences/SampleServiceProvider/Reference.svcmap
@@ -20,6 +20,7 @@
<MetadataSource Address="http://localhost:65169/ServiceProvider/DataApi.svc" Protocol="http" SourceId="1" />
</MetadataSources>
<Metadata>
+ <MetadataFile FileName="DataApi2.xsd" MetadataType="Schema" ID="232b71c0-94e9-43eb-9b23-fe9a229dce94" SourceId="1" SourceUrl="http://localhost:65169/ServiceProvider/DataApi.svc?xsd=xsd2" />
<MetadataFile FileName="DataApi.xsd" MetadataType="Schema" ID="fdc9f289-8c10-4fc6-abeb-052bc1116679" SourceId="1" SourceUrl="http://localhost:65169/ServiceProvider/DataApi.svc?xsd=xsd1" />
<MetadataFile FileName="DataApi.wsdl" MetadataType="Wsdl" ID="182a10fe-d606-4fc0-b64c-3e682dcae89d" SourceId="1" SourceUrl="http://localhost:65169/ServiceProvider/DataApi.svc?wsdl" />
<MetadataFile FileName="DataApi1.xsd" MetadataType="Schema" ID="80d06927-f2e7-4d1d-8c7a-f3dc74f4d3d6" SourceId="1" SourceUrl="http://localhost:65169/ServiceProvider/DataApi.svc?xsd=xsd0" />
diff --git a/samples/Consumer/SampleWcf.aspx b/samples/Consumer/SampleWcf.aspx
index aad8a88..6dfd56e 100644
--- a/samples/Consumer/SampleWcf.aspx
+++ b/samples/Consumer/SampleWcf.aspx
@@ -2,12 +2,23 @@
CodeFile="SampleWcf.aspx.cs" Inherits="SampleWcf" %>
<asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="Server">
- <asp:Button ID="getAuthorizationButton" runat="server" Text="Get Authorization" OnClick="getAuthorizationButton_Click" />
- <asp:Label ID="authorizationLabel" runat="server" />
+ <fieldset title="Authorization">
+ <asp:CheckBoxList runat="server" ID="scopeList">
+ <asp:ListItem Value="http://tempuri.org/IDataApi/GetName">GetName</asp:ListItem>
+ <asp:ListItem Value="http://tempuri.org/IDataApi/GetAge">GetAge</asp:ListItem>
+ <asp:ListItem Value="http://tempuri.org/IDataApi/GetFavoriteSites">GetFavoriteSites</asp:ListItem>
+ </asp:CheckBoxList>
+ <asp:Button ID="getAuthorizationButton" runat="server" Text="Get Authorization" OnClick="getAuthorizationButton_Click" />
+ <asp:Label ID="authorizationLabel" runat="server" />
+ </fieldset>
<br />
<asp:Button ID="getNameButton" runat="server" Text="Get Name" OnClick="getNameButton_Click" />
<asp:Label ID="nameLabel" runat="server" />
<br />
<asp:Button ID="getAgeButton" runat="server" Text="Get Age" OnClick="getAgeButton_Click" />
<asp:Label ID="ageLabel" runat="server" />
+ <br />
+ <asp:Button ID="getFavoriteSites" runat="server" Text="Get Favorite Sites"
+ onclick="getFavoriteSites_Click" />
+ <asp:Label ID="favoriteSitesLabel" runat="server" />
</asp:Content>
diff --git a/samples/Consumer/SampleWcf.aspx.cs b/samples/Consumer/SampleWcf.aspx.cs
index c1e0209..b06446f 100644
--- a/samples/Consumer/SampleWcf.aspx.cs
+++ b/samples/Consumer/SampleWcf.aspx.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Globalization;
using System.Net;
using System.ServiceModel;
@@ -7,6 +8,9 @@ using DotNetOAuth;
using DotNetOAuth.ChannelElements;
using DotNetOAuth.Messaging;
using SampleServiceProvider;
+using System.Collections.Generic;
+using System.Web.UI.WebControls;
+using System.ServiceModel.Security;
/// <summary>
/// Sample consumer of our Service Provider sample's WCF service.
@@ -27,22 +31,50 @@ public partial class SampleWcf : System.Web.UI.Page {
protected void getAuthorizationButton_Click(object sender, EventArgs e) {
Consumer consumer = this.CreateConsumer();
- consumer.RequestUserAuthorization().Send();
+ UriBuilder callback = new UriBuilder(Request.Url);
+ callback.Query = null;
+ string scope = string.Join("|", (from item in scopeList.Items.OfType<ListItem>()
+ where item.Selected
+ select item.Value).ToArray());
+ var requestParams = new Dictionary<string, string> {
+ { "scope", scope },
+ };
+ consumer.RequestUserAuthorization(callback.Uri, requestParams, null).Send();
}
protected void getNameButton_Click(object sender, EventArgs e) {
- nameLabel.Text = CallService(client => client.GetName());
+ try {
+ nameLabel.Text = CallService(client => client.GetName());
+ } catch (SecurityAccessDeniedException) {
+ nameLabel.Text = "Access denied!";
+ }
}
protected void getAgeButton_Click(object sender, EventArgs e) {
- int? age = CallService(client => client.GetAge());
- ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available";
+ try {
+ int? age = CallService(client => client.GetAge());
+ ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available";
+ } catch (SecurityAccessDeniedException) {
+ ageLabel.Text = "Access denied!";
+ }
+ }
+
+ protected void getFavoriteSites_Click(object sender, EventArgs e) {
+ try {
+ string[] favoriteSites = CallService(client => client.GetFavoriteSites());
+ favoriteSitesLabel.Text = string.Join(", ", favoriteSites);
+ } catch (SecurityAccessDeniedException) {
+ favoriteSitesLabel.Text = "Access denied!";
+ }
}
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;
+ if (accessToken == null) {
+ throw new InvalidOperationException("No access token!");
+ }
Consumer consumer = this.CreateConsumer();
WebRequest httpRequest = consumer.CreateAuthorizedRequest(serviceEndpoint, accessToken);