Skip to content

Commit bbc14b7

Browse files
nanddeepnVesaJuvonen
authored andcommitted
Link and Code Formatting updates (SharePoint#4589)
"AdventureWorks 20012 LT script" renamed to "AdventureWorks 2012 LT script". Hyperlink for Script and Data is pointed to https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks Formatted code samples Formatted headers for Note sections
1 parent aa76d82 commit bbc14b7

File tree

1 file changed

+54
-61
lines changed

1 file changed

+54
-61
lines changed

docs/general-development/how-to-create-an-odata-data-service-for-use-as-a-bcs-external-system.md

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ The following are required to create the OData service in this article:
3434
- SharePoint
3535

3636

37-
- [AdventureWorks 20012 LT script](http://msftdbprodsamples.codeplex.com/releases/view/55330)
37+
- [AdventureWorks 2012 LT script](https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks)
3838

3939

40-
- [AdventureWorks 2012 LT Data](http://msftdbprodsamples.codeplex.com/releases/view/55330)
40+
- [AdventureWorks 2012 LT Data](https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks)
4141

4242

4343
- Visual Studio 2012
@@ -198,16 +198,14 @@ By default, when a WCF service is created, it cannot be accessed due to its secu
198198
- In the code for the data service, replace the placeholder code in the **InitializeService** function with the following.
199199

200200
```cs
201-
202-
config.SetEntitySetAccessRule("*", EntitySetRights.All);
203-
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
201+
config.SetEntitySetAccessRule("*", EntitySetRights.All);
202+
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
204203
```
205-
206-
207-
This enables authorized clients to have read and write access to resources for the specified entity sets.
204+
This enables authorized clients to have read and write access to resources for the specified entity sets.
205+
208206

209-
> [!NOTE]
210-
> Any client that can access the ASP.NET application can also access the resources that are exposed by the data service. In a production data service, to prevent unauthorized access to resources, you should also secure the application itself. For more information, see [Securing WCF Data Services](http://msdn.microsoft.com/en-us/library/dd728284.aspx).
207+
> [!NOTE]
208+
> Any client that can access the ASP.NET application can also access the resources that are exposed by the data service. In a production data service, to prevent unauthorized access to resources, you should also secure the application itself. For more information, see [Securing WCF Data Services](http://msdn.microsoft.com/en-us/library/dd728284.aspx).
211209
212210
For BCS to receive notifications, there must be a mechanism on the back-end data source that will accept a request to be added and removed from notification subscriptions.
213211

@@ -224,74 +222,69 @@ The last step in creating the service is to add service operations for the **Sub
224222
- In the AdventureWorks.cs page, add the following string variable declaration.
225223

226224
```cs
227-
228225
public string subscriptionStorePath = @"\\\\[SHARE_NAME]\\SubscriptionStore\\SubscriptionStore.xml";
229226
```
230227

228+
> [!NOTE]
229+
> This file is an XML file that is updated with the new subscriptions. Access to this file will be made by the server process, so make sure you have granted sufficient rights for this file access. > You might also want to create a database solution for storing subscription information.
231230
232-
> [!NOTE]
233-
> This file is an XML file that is updated with the new subscriptions. Access to this file will be made by the server process, so make sure you have granted sufficient rights for this file access. > You might also want to create a database solution for storing subscription information.
231+
Then add the following two **WebGet** methods to handle the subscriptions.
234232

235-
Then add the following two **WebGet** methods to handle the subscriptions.
236-
233+
```cs
234+
[WebGet]
235+
public string Subscribe(string deliveryUrl, string eventType)
236+
{
237+
string subscriptionId = Guid.NewGuid().ToString();
237238

239+
XmlDocument subscriptionStore = new XmlDocument();
238240

239-
```cs
240-
[WebGet]
241-
public string Subscribe(string deliveryUrl, string eventType)
242-
{
243-
string subscriptionId = Guid.NewGuid().ToString();
244-
245-
XmlDocument subscriptionStore = new XmlDocument();
246-
247-
subscriptionStore.Load(subscriptionStorePath);
241+
subscriptionStore.Load(subscriptionStorePath);
248242

249-
// Add a new subscription element.
250-
XmlNode newSubNode = subscriptionStore.CreateElement("Subscription");
243+
// Add a new subscription element.
244+
XmlNode newSubNode = subscriptionStore.CreateElement("Subscription");
251245

252-
// Add subscription ID element to the subscription element.
253-
XmlNode subscriptionIdStart = subscriptionStore.CreateElement("SubscriptionID");
254-
subscriptionIdStart.InnerText = subscriptionId;
255-
newSubNode.AppendChild(subscriptionIdStart);
246+
// Add subscription ID element to the subscription element.
247+
XmlNode subscriptionIdStart = subscriptionStore.CreateElement("SubscriptionID");
248+
subscriptionIdStart.InnerText = subscriptionId;
249+
newSubNode.AppendChild(subscriptionIdStart);
256250

257-
// Add delivery URL element to the subscription element.
258-
XmlNode deliveryAddressStart = subscriptionStore.CreateElement("DeliveryAddress");
259-
deliveryAddressStart.InnerText = deliveryUrl;
260-
newSubNode.AppendChild(deliveryAddressStart);
251+
// Add delivery URL element to the subscription element.
252+
XmlNode deliveryAddressStart = subscriptionStore.CreateElement("DeliveryAddress");
253+
deliveryAddressStart.InnerText = deliveryUrl;
254+
newSubNode.AppendChild(deliveryAddressStart);
261255

262-
// Add event type element to the subscription element.
263-
XmlNode eventTypeStart = subscriptionStore.CreateElement("EventType");
264-
eventTypeStart.InnerText = eventType;
265-
newSubNode.AppendChild(eventTypeStart);
256+
// Add event type element to the subscription element.
257+
XmlNode eventTypeStart = subscriptionStore.CreateElement("EventType");
258+
eventTypeStart.InnerText = eventType;
259+
newSubNode.AppendChild(eventTypeStart);
266260

267-
// Add the subscription element to the root element.
268-
subscriptionStore.AppendChild(newSubNode);
261+
// Add the subscription element to the root element.
262+
subscriptionStore.AppendChild(newSubNode);
269263

270-
271-
subscriptionStore.Save(subscriptionStorePath);
264+
subscriptionStore.Save(subscriptionStorePath);
272265

273-
return subscriptionId;
274-
}
266+
return subscriptionId;
267+
}
268+
269+
[WebGet]
270+
public void Unsubscribe(string subscriptionId)
271+
{
272+
XmlDocument subscriptionStore = new XmlDocument();
273+
subscriptionStore.Load(subscriptionStorePath);
275274

276-
[WebGet]
277-
public void Unsubscribe(string subscriptionId)
275+
XmlNodeList subscriptions = subscriptionStore.DocumentElement.ChildNodes;
276+
foreach (XmlNode subscription in subscriptions)
277+
{
278+
XmlNodeList subscriptionList = subscription.ChildNodes;
279+
if (subscriptionList.Item(0).InnerText == subscriptionId)
278280
{
279-
XmlDocument subscriptionStore = new XmlDocument();
280-
subscriptionStore.Load(subscriptionStorePath);
281-
282-
XmlNodeList subscriptions = subscriptionStore.DocumentElement.ChildNodes;
283-
foreach (XmlNode subscription in subscriptions)
284-
{
285-
XmlNodeList subscriptionList = subscription.ChildNodes;
286-
if (subscriptionList.Item(0).InnerText == subscriptionId)
287-
{
288-
subscriptionStore.DocumentElement.RemoveChild(subscription);
289-
break;
290-
}
291-
}
292-
293-
subscriptionStore.Save(subscriptionStorePath);
281+
subscriptionStore.DocumentElement.RemoveChild(subscription);
282+
break;
294283
}
284+
}
285+
286+
subscriptionStore.Save(subscriptionStorePath);
287+
}
295288

296289
```
297290

0 commit comments

Comments
 (0)