Feb
28
Written by:
Michael Washington
2/28/2012 8:28 AM
You may have the need to access your custom LightSwitch WCF RIA Services from outside of LightSwitch using OData. This article will show you how.
We start with the code from the article: WCF RIA Service: Combining Two Tables.
The first thing we do is add:
[EnableClientAccess()]
To the WCF RIA Class. This allows us to call the method from outside of LightSwitch.
Note: Now anyone can get to your web methods! So see: Simple Example To Secure WCF Data Service OData Methods http://openlightgroup.net/Blog/tabid/58/BlogID/1/Default.aspx
We also add a reference to System.ServiceModel.DomainServices.Hosting.OData.
Next we click on the LightSwitch project in the Solution Explorer, and switch to File View.
We then select Show All Files.
We add the following code to the Configuration section in the Web.config:
<configSections>
<sectionGroup name="system.serviceModel">
<section name="domainServices"
type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection,
System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</sectionGroup>
</configSections>
We also add the following code to the system.serviceModel tag (you will see an squiggly blue line under domainServices that you can ignore):
<domainServices>
<endpoints>
<add name="OData"
type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory,
System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</endpoints>
</domainServices>
We switch back to Logical View and go into project Properties.
We change the application to a Web application.
When we launch the application we see the normal URL.
If we change the URL to:
WCF_RIA_Project-WCF_RIA_Service.svc/OData/
We see the OData feed.
You create the URL by using this format:
{namespace}-{class name}.svc/OData
Using LinqPad
We can download and install LinqPad from: http://www.linqpad.net/.
We add a connection.
We select OData.
We enter the URL.
We can now query the OData feed.
Also See
Simple Example To Secure WCF Data Service OData Methods
http://openlightgroup.net/Blog/tabid/58/BlogID/1/Default.aspx
Download Code
The LightSwitch project is available at:
http://lightswitchhelpwebsite.com/Downloads.aspx
1 comment(s) so far...
And that, my friends, just blew LightSwitch WIIIIIDE open!
By Jan Van der Haegen on
2/28/2012 9:24 AM
|