You are here:   Blog
Register   |  Login

 

Feb 28

Written by: Michael Washington
2/28/2012 8:28 AM  RssIcon

image

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.

image

We start with the code from the article: WCF RIA Service: Combining Two Tables.

image

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

image

We also add a reference to System.ServiceModel.DomainServices.Hosting.OData.

image

Next we click on the LightSwitch project in the Solution Explorer, and switch to File View.

image

We then select Show All Files.

image

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>

 

image

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>

image

We switch back to Logical View and go into project Properties.

image

We change the application to a Web application.

image

When we launch the application we see the normal URL.

image

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

image

We can download and install LinqPad from: http://www.linqpad.net/.

image

We add a connection.

image

We select OData.

image

We enter the URL.

image

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

Tags: OData
Categories:

1 comment(s) so far...


Gravatar

Re: Calling Your Custom WCF RIA Services Using OData

And that, my friends, just blew LightSwitch WIIIIIDE open!

By Jan Van der Haegen on   2/28/2012 9:24 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation