<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Michael Maddox - Software Development - OData</title>
    <link>http://www.capprime.com/software_development_weblog/</link>
    <description>Best Practices, Knowlegde Base Type Articles, General Tech Opinions, etc.</description>
    <language>en-us</language>
    <copyright>Michael Maddox</copyright>
    <lastBuildDate>Sat, 07 Aug 2010 11:49:17 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>Michael.P.Maddox@gmail.com</managingEditor>
    <webMaster>Michael.P.Maddox@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.capprime.com/software_development_weblog/Trackback.aspx?guid=4839bf08-5a1b-4b2a-954d-aa90d0f3f979</trackback:ping>
      <pingback:server>http://www.capprime.com/software_development_weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.capprime.com/software_development_weblog/PermaLink,guid,4839bf08-5a1b-4b2a-954d-aa90d0f3f979.aspx</pingback:target>
      <dc:creator>Michael Maddox</dc:creator>
      <wfw:comment>http://www.capprime.com/software_development_weblog/CommentView,guid,4839bf08-5a1b-4b2a-954d-aa90d0f3f979.aspx</wfw:comment>
      <wfw:commentRss>http://www.capprime.com/software_development_weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=4839bf08-5a1b-4b2a-954d-aa90d0f3f979</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Consuming OData from Silverlight 4 can be a very frustrating experience for people
like me who are just now joining the Silverlight party.
</p>
        <p>
When it doesn't work, it can fail silently and/or with incorrectly worded warnings.
</p>
        <p>
This is a perfect example of where a blog post can hopefully fill in some of the gaps
left by the Microsoft documentation.
</p>
        <p>
First, let's setup a very simple Silverlight 4 application against the odata.org Northwind
service.
</p>
        <p>
Note: You may need to install the Silverlight 4 Tools for VS 2010 for this sample.<br />
 <a href="http://www.bing.com/search?q=Microsoft+Silverlight+4+Tools+for+Visual+Studio+2010">http://www.bing.com/search?q=Microsoft+Silverlight+4+Tools+for+Visual+Studio+2010</a></p>
        <p>
In Visual Studio 2010:
</p>
        <p>
File -&gt; New -&gt; Project<br />
 Visual C# -&gt; Silverlight -&gt; Silverlight Application -&gt; OK<br />
  New Silverlight Application wizard<br />
   Uncheck "Host the Silverlight application in a new website"<br />
   Silverlight Version: Silverlight 4<br />
   OK
</p>
        <p>
Right Click References in Solution Explorer -&gt; Add Service Reference...<br />
 Address: <a href="http://services.odata.org/Northwind/Northwind.svc/">http://services.odata.org/Northwind/Northwind.svc/</a><br />
 Namespace: RemoteNorthwindServiceReference<br />
 OK
</p>
        <p>
From the toolbox, drag and drop a DataGrid from the "Common Silverlight Controls"
section onto MainPage.xaml<br />
 Change the AutoGenerateColumns property to True<br />
 Change the Margin to 0,0,0,0<br />
 Change the Width to 400
</p>
        <p>
In MainPage.xaml.cs:<br />
 Add the following using statement:
</p>
        <p>
  <font face="Consolas" color="#0000ff" size="2"><font face="Consolas" color="#0000ff" size="2"><font face="Consolas" color="#0000ff" size="2">using</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2"><font color="#000000"> System.Data.Services.Client;</font></font></font></p>
        <p>
 Add the following class variable:
</p>
        <p>
  <font face="Consolas" color="#0000ff" size="2"><font face="Consolas" color="#0000ff" size="2"><font face="Consolas" color="#0000ff" size="2">private</font></font></font><font face="Consolas" size="2"><font face="Consolas" color="#000000" size="2"></font></font><font face="Consolas" color="#2b91af" size="2"><font face="Consolas" color="#2b91af" size="2"><font face="Consolas" color="#2b91af" size="2">DataServiceCollection</font></font></font><font face="Consolas" size="2"><font face="Consolas" color="#000000" size="2">&lt;RemoteNorthwindServiceReference.</font></font><font face="Consolas" color="#2b91af" size="2"><font face="Consolas" color="#2b91af" size="2"><font face="Consolas" color="#2b91af" size="2">Shipper</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2"><font color="#000000">&gt;
_shippers;</font></font></font></p>
        <p>
 Add the following to the bottom of the MainPage constructor method:
</p>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">
            <p>
  RemoteNorthwindServiceReference.
</p>
          </font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">NorthwindEntities</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> remoteNorthwindService
=<br /></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">   
new</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> RemoteNorthwindServiceReference.</font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">NorthwindEntities</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">(<br /></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">     
new</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">
          </font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">Uri</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">(</font>
        </font>
        <font face="Consolas" color="#a31515" size="2">
          <font face="Consolas" color="#a31515" size="2">
            <font face="Consolas" color="#a31515" size="2">"http://services.odata.org/Northwind/Northwind.svc/"</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">));
<p>
  _shippers = 
</p></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">new</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">
          </font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">DataServiceCollection</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">&lt;RemoteNorthwindServiceReference.</font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">Shipper</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">&gt;();<br />
  _shippers.LoadCompleted += </font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">new</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">
          </font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">EventHandler</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">&lt;</font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">LoadCompletedEventArgs</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">&gt;(_shippers_LoadCompleted);
<p></p></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2"> 
var</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> query
= </font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">from</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> shippers </font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">in</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> remoteNorthwindService.Shippers </font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">select</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> shippers;<br />
  _shippers.LoadAsync(query);
</font>
        </font>
        <p>
 Add the following new method:
</p>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">
            <p>
            </p>
          </font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2"> 
private</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">
          </font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">void</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> _shippers_LoadCompleted(</font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">object</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> sender, </font>
        </font>
        <font face="Consolas" color="#2b91af" size="2">
          <font face="Consolas" color="#2b91af" size="2">
            <font face="Consolas" color="#2b91af" size="2">LoadCompletedEventArgs</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> e)<br />
  {<br /></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">   
if</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2"> (_shippers.Continuation
!= </font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">null</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">)<br /><font color="#0000ff">    </font>{<br /><font color="#0000ff">      </font>_shippers.LoadNextPartialSetAsync();<br /><font color="#0000ff">    </font>}<br /></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">   
else<br /></font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">
            <font color="#0000ff">    </font>{<br /></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">     
this</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">.dataGrid1.ItemsSource
= _shippers;<br /></font>
        </font>
        <font face="Consolas" color="#0000ff" size="2">
          <font face="Consolas" color="#0000ff" size="2">
            <font face="Consolas" color="#0000ff" size="2">     
this</font>
          </font>
        </font>
        <font face="Consolas" size="2">
          <font face="Consolas" size="2">.dataGrid1.UpdateLayout();<br /><font color="#0000ff">    </font>}<br />
  }
</font>
        </font>
        <p>
Debug -&gt; Start Without Debugging<br />
 You should get a dialog box titled "Silverlight Project" that says:<br />
  "The Silverlight project you are about to debug uses web services. 
Calls to the web service will fail unless the Silverlight project is hosted in and
launched from the same web project that contains the web services.  Do you want
to debug anyway?"<br />
 Click "Yes"
</p>
        <p>
This application runs fine.  The warning dialog message was obviously inaccurate
and misleading.
</p>
        <p>
I wish I would have understood what this warning dialog was trying to say, but since
the remote OData service was working, I had no real choice but to ignore the dialog,
which would haunt me when trying to use the same application to call a local OData
service.
</p>
        <p>
I believe this dialog is trying to warn you that Silverlight has special constraints
when calling web services, but it's still not clear to me what those are.  Proceed
cautiously.
</p>
        <p>
Here is one way to successfully call a local OData webservice from Silverlight 4 in
Visual Studio 10:
</p>
        <p>
File -&gt; New -&gt; Project<br />
 Visual C# -&gt; Silverlight -&gt; Silverlight Application -&gt; OK<br />
  New Silverlight Application wizard<br />
   OK (Accept the defaults: ASP.NET Web Application Project, Silverlight
4, etc.)
</p>
        <p>
Right Click SilverlightApplication&lt;number&gt;.Web in Solution Explorer -&gt; Add
New Item...<br />
 Visual C# -&gt; Data -&gt; ADO.NET Entity Data Model -&gt; Add<br />
  Entity Data Model Wizard<br />
   Next (Generate from database - this assumes you have Northwind running
locally)<br />
   New Connection... -&gt; Point to your local Northwind Database Server
-&gt; Next<br />
   Select the Tables check box (to select all tables) -&gt; Finish
</p>
        <p>
Right Click SilverlightApplication&lt;number&gt;.Web in Solution Explorer -&gt; Add
New Item...<br />
 Visual C# -&gt; Web -&gt; WCF Data Service -&gt; Add
</p>
        <p>
In WcfDataService1.cs:<br />
 Replace " /* TODO: put your data source class name here */ " with "NorthwindEntities"
(no quotes)<br />
 Add the following line to the InitializeService method:
</p>
        <p>
  <font face="Consolas" size="2"><font face="Consolas" size="2">config.SetEntitySetAccessRule(</font></font><font face="Consolas" color="#a31515" size="2"><font face="Consolas" color="#a31515" size="2"><font face="Consolas" color="#a31515" size="2">"*"</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">, </font></font><font face="Consolas" color="#2b91af" size="2"><font face="Consolas" color="#2b91af" size="2"><font face="Consolas" color="#2b91af" size="2">EntitySetRights</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.AllRead);
</font></font></p>
        <p>
Debug -&gt; Start Without Debugging
</p>
        <p>
Right Click References under SilverlightApplication&lt;number&gt; in Solution Explorer
-&gt; Add Service Reference...<br />
 Discover -&gt; Services In Solution (note the port number of the discovered
service, you will need it below)<br />
 Namespace: LocalNorthwindServiceReference<br />
 OK
</p>
        <p>
Stop the browser that was started above
</p>
        <p>
Follow the same basic steps as the first example above to modify MainPage except:<br />
 Replace RemoteNorthwindServiceReference with LocalNorthwindServiceReference 
<br />
 Replace "<a href="http://services.odata.org/Northwind/Northwind.svc/">http://services.odata.org/Northwind/Northwind.svc/</a>"
with "http://localhost:&lt;port number noted above&gt;/WcfDataService1.svc/"
</p>
        <p>
Debug -&gt; Start Without Debugging
</p>
        <p>
This application runs fine (without the warning dialog this time).
</p>
        <p>
It can be ridiculously difficult to get a local OData service working with Silverlight
4 if you don't carefully dance around the project setup issues.<br />
The warning dialog when you start debugging is nearly useless and the app will return
no data with no apparent errors if you setup the project incorrectly.
</p>
        <p>
Some references I found useful while building this sample:
</p>
        <p>
 MSDN: How to: Create the Northwind Data Service (WCF Data Services/Silverlight)<br />
 <a href="http://msdn.microsoft.com/en-us/library/cc838239(VS.95).aspx">http://msdn.microsoft.com/en-us/library/cc838239(VS.95).aspx</a></p>
        <p>
 Audrey PETIT's blog: Use OData data with WCF Data Services and Silverlight 4<br />
 <a href="http://msmvps.com/blogs/audrey/archive/2010/06/10/odata-use-odata-data-with-wcf-data-services-and-silverlight-4.aspx">http://msmvps.com/blogs/audrey/archive/2010/06/10/odata-use-odata-data-with-wcf-data-services-and-silverlight-4.aspx</a></p>
        <p>
 Darrel Miller's Bizcoder blog: World’s simplest OData service<br />
 <a href="http://www.bizcoder.com/index.php/2010/03/26/worlds-simplest-odata-service/">http://www.bizcoder.com/index.php/2010/03/26/worlds-simplest-odata-service/</a></p>
        <p>
Once you deploy your OData service to a real web hosting environment, you'll likely
need to do some special setup to access your OData service from Silverlight 4 (clientaccesspolicy.xml
/ crossdomain.xml):
</p>
        <p>
 Making a Service Available Across Domain Boundaries<br />
 <a href="http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx">http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx</a></p>
        <p>
Tremendous thanks go out to <a href="http://www.ignitionpointsolutions.com/Blog/tabid/56/Default.aspx">Scott
Davis of Ignition Point Solutions</a> for pointing me to the flawed project setup
as the reason I couldn't get this working initially.<br /></p>
        <img width="0" height="0" src="http://www.capprime.com/software_development_weblog/aggbug.ashx?id=4839bf08-5a1b-4b2a-954d-aa90d0f3f979" />
      </body>
      <title>Consuming OData from Silverlight 4 with Visual Studio 2010</title>
      <guid isPermaLink="false">http://www.capprime.com/software_development_weblog/PermaLink,guid,4839bf08-5a1b-4b2a-954d-aa90d0f3f979.aspx</guid>
      <link>http://www.capprime.com/software_development_weblog/2010/08/07/ConsumingODataFromSilverlight4WithVisualStudio2010.aspx</link>
      <pubDate>Sat, 07 Aug 2010 11:49:17 GMT</pubDate>
      <description>&lt;p&gt;
Consuming OData from Silverlight 4 can be a very frustrating experience for people
like me who are just now joining the Silverlight party.
&lt;/p&gt;
&lt;p&gt;
When it doesn't work, it can fail silently and/or with incorrectly worded warnings.
&lt;/p&gt;
&lt;p&gt;
This is a perfect example of where a blog post can hopefully fill in some of the gaps
left by the Microsoft documentation.
&lt;/p&gt;
&lt;p&gt;
First, let's setup a very simple Silverlight 4 application against the odata.org Northwind
service.
&lt;/p&gt;
&lt;p&gt;
Note: You may need to install the Silverlight 4 Tools for VS 2010 for this sample.&lt;br&gt;
&amp;nbsp;&lt;a href="http://www.bing.com/search?q=Microsoft+Silverlight+4+Tools+for+Visual+Studio+2010"&gt;http://www.bing.com/search?q=Microsoft+Silverlight+4+Tools+for+Visual+Studio+2010&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In Visual Studio 2010:
&lt;/p&gt;
&lt;p&gt;
File -&amp;gt; New -&amp;gt; Project&lt;br&gt;
&amp;nbsp;Visual C# -&amp;gt; Silverlight -&amp;gt; Silverlight Application -&amp;gt; OK&lt;br&gt;
&amp;nbsp;&amp;nbsp;New Silverlight Application wizard&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Uncheck "Host the Silverlight application in a new website"&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Silverlight Version: Silverlight 4&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;OK
&lt;/p&gt;
&lt;p&gt;
Right Click References in Solution Explorer -&amp;gt; Add Service Reference...&lt;br&gt;
&amp;nbsp;Address: &lt;a href="http://services.odata.org/Northwind/Northwind.svc/"&gt;http://services.odata.org/Northwind/Northwind.svc/&lt;/a&gt;
&lt;br&gt;
&amp;nbsp;Namespace: RemoteNorthwindServiceReference&lt;br&gt;
&amp;nbsp;OK
&lt;/p&gt;
&lt;p&gt;
From the toolbox, drag and drop a DataGrid from the "Common Silverlight Controls"
section onto MainPage.xaml&lt;br&gt;
&amp;nbsp;Change the AutoGenerateColumns property to True&lt;br&gt;
&amp;nbsp;Change the Margin to 0,0,0,0&lt;br&gt;
&amp;nbsp;Change the Width to 400
&lt;/p&gt;
&lt;p&gt;
In MainPage.xaml.cs:&lt;br&gt;
&amp;nbsp;Add the following using statement:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;using&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;&lt;font color=#000000&gt; System.Data.Services.Client;&lt;/font&gt;
&lt;/p&gt;
&gt;&gt; 
&lt;p&gt;
&amp;nbsp;Add the following class variable:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;private&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas color=#000000 size=2&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;DataServiceCollection&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas color=#000000 size=2&gt;&amp;lt;RemoteNorthwindServiceReference.&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;Shipper&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;&lt;font color=#000000&gt;&amp;gt;
_shippers;&lt;/font&gt;
&lt;/p&gt;
&gt;&gt; 
&lt;p&gt;
&amp;nbsp;Add the following to the bottom of the MainPage constructor method:
&lt;/p&gt;
&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; 
&lt;p&gt;
&amp;nbsp; RemoteNorthwindServiceReference.
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;NorthwindEntities&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; remoteNorthwindService
=&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
new&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; RemoteNorthwindServiceReference.&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;NorthwindEntities&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;(&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
new&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;Uri&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;(&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#a31515 size=2&gt;&lt;font face=Consolas color=#a31515 size=2&gt;&lt;font face=Consolas color=#a31515 size=2&gt;"http://services.odata.org/Northwind/Northwind.svc/"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;));&gt;
&lt;p&gt;
&amp;nbsp; _shippers = 
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;new&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;DataServiceCollection&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;&amp;lt;RemoteNorthwindServiceReference.&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;Shipper&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;&amp;gt;();&lt;br&gt;
&amp;nbsp; _shippers.LoadCompleted += &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;new&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;EventHandler&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;&amp;lt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;LoadCompletedEventArgs&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;&amp;gt;(_shippers_LoadCompleted);&gt;
&lt;p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;
var&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; query
= &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;from&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; shippers &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;in&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; remoteNorthwindService.Shippers &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;select&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; shippers;&lt;br&gt;
&amp;nbsp; _shippers.LoadAsync(query);&gt;
&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;
&amp;nbsp;Add the following new method:
&lt;/p&gt;
&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;
private&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;void&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; _shippers_LoadCompleted(&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;object&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; sender, &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;LoadCompletedEventArgs&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; e)&lt;br&gt;
&amp;nbsp; {&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
if&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt; (_shippers.Continuation
!= &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;null&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;)&lt;br&gt;
&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;
&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;_shippers.LoadNextPartialSetAsync();&lt;br&gt;
&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
else&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;{&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
this&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;.dataGrid1.ItemsSource
= _shippers;&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&lt;font face=Consolas color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
this&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;.dataGrid1.UpdateLayout();&lt;br&gt;
&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;}&lt;br&gt;
&amp;nbsp; }&gt;
&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;
Debug -&amp;gt; Start Without Debugging&lt;br&gt;
&amp;nbsp;You should get a dialog box titled "Silverlight Project" that says:&lt;br&gt;
&amp;nbsp;&amp;nbsp;"The Silverlight project you are about to debug uses web services.&amp;nbsp;
Calls to the web service will fail unless the Silverlight project is hosted in and
launched from the same web project that contains the web services.&amp;nbsp; Do you want
to debug anyway?"&lt;br&gt;
&amp;nbsp;Click "Yes"
&lt;/p&gt;
&lt;p&gt;
This application runs fine.&amp;nbsp; The warning dialog message was obviously inaccurate
and misleading.
&lt;/p&gt;
&lt;p&gt;
I wish I would have understood what this warning dialog was trying to say, but since
the remote OData service was working, I had no real choice but to ignore the dialog,
which would haunt me when trying to use the same application to call a local OData
service.
&lt;/p&gt;
&lt;p&gt;
I believe this dialog is trying to warn you that Silverlight has special constraints
when calling web services, but it's still not clear to me what those are.&amp;nbsp; Proceed
cautiously.
&lt;/p&gt;
&lt;p&gt;
Here is one way to successfully call a local OData webservice from Silverlight 4 in
Visual Studio 10:
&lt;/p&gt;
&lt;p&gt;
File -&amp;gt; New -&amp;gt; Project&lt;br&gt;
&amp;nbsp;Visual C# -&amp;gt; Silverlight -&amp;gt; Silverlight Application -&amp;gt; OK&lt;br&gt;
&amp;nbsp;&amp;nbsp;New Silverlight Application wizard&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;OK (Accept the defaults: ASP.NET Web Application Project, Silverlight
4, etc.)
&lt;/p&gt;
&lt;p&gt;
Right Click SilverlightApplication&amp;lt;number&amp;gt;.Web in Solution Explorer -&amp;gt; Add
New Item...&lt;br&gt;
&amp;nbsp;Visual C# -&amp;gt; Data -&amp;gt; ADO.NET Entity Data Model -&amp;gt; Add&lt;br&gt;
&amp;nbsp;&amp;nbsp;Entity Data Model Wizard&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Next (Generate from database - this assumes you have Northwind running
locally)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;New Connection... -&amp;gt; Point to your local Northwind Database Server
-&amp;gt; Next&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Select the Tables check box (to select all tables) -&amp;gt; Finish
&lt;/p&gt;
&lt;p&gt;
Right Click SilverlightApplication&amp;lt;number&amp;gt;.Web in Solution Explorer -&amp;gt; Add
New Item...&lt;br&gt;
&amp;nbsp;Visual C# -&amp;gt; Web -&amp;gt; WCF Data Service -&amp;gt; Add
&lt;/p&gt;
&lt;p&gt;
In WcfDataService1.cs:&lt;br&gt;
&amp;nbsp;Replace " /* TODO: put your data source class name here */ " with "NorthwindEntities"
(no quotes)&lt;br&gt;
&amp;nbsp;Add the following line to the InitializeService method:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;config.SetEntitySetAccessRule(&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#a31515 size=2&gt;&lt;font face=Consolas color=#a31515 size=2&gt;&lt;font face=Consolas color=#a31515 size=2&gt;"*"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;, &lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;&lt;font face=Consolas color=#2b91af size=2&gt;EntitySetRights&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face=Consolas size=2&gt;&lt;font face=Consolas size=2&gt;.AllRead);
&lt;/p&gt;
&gt;&gt; 
&lt;p&gt;
Debug -&amp;gt; Start Without Debugging
&lt;/p&gt;
&lt;p&gt;
Right Click References under SilverlightApplication&amp;lt;number&amp;gt; in Solution Explorer
-&amp;gt; Add Service Reference...&lt;br&gt;
&amp;nbsp;Discover -&amp;gt; Services In Solution (note the port number of the discovered
service, you will need it below)&lt;br&gt;
&amp;nbsp;Namespace: LocalNorthwindServiceReference&lt;br&gt;
&amp;nbsp;OK
&lt;/p&gt;
&lt;p&gt;
Stop the browser that was started above
&lt;/p&gt;
&lt;p&gt;
Follow the same basic steps as the first example above to modify MainPage except:&lt;br&gt;
&amp;nbsp;Replace RemoteNorthwindServiceReference with LocalNorthwindServiceReference 
&lt;br&gt;
&amp;nbsp;Replace "&lt;a href="http://services.odata.org/Northwind/Northwind.svc/"&gt;http://services.odata.org/Northwind/Northwind.svc/&lt;/a&gt;"
with "http://localhost:&amp;lt;port number noted above&amp;gt;/WcfDataService1.svc/"
&lt;/p&gt;
&lt;p&gt;
Debug -&amp;gt; Start Without Debugging
&lt;/p&gt;
&lt;p&gt;
This application runs fine (without the warning dialog this time).
&lt;/p&gt;
&lt;p&gt;
It can be ridiculously difficult to get a local OData service working with Silverlight
4 if you don't carefully dance around the project setup issues.&lt;br&gt;
The warning dialog when you start debugging is nearly useless and the app will return
no data with no apparent errors if you setup the project incorrectly.
&lt;/p&gt;
&lt;p&gt;
Some references I found useful while building this sample:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;MSDN: How to: Create the Northwind Data Service (WCF Data Services/Silverlight)&lt;br&gt;
&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/cc838239(VS.95).aspx"&gt;http://msdn.microsoft.com/en-us/library/cc838239(VS.95).aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;Audrey PETIT's blog: Use OData data with WCF Data Services and Silverlight 4&lt;br&gt;
&amp;nbsp;&lt;a href="http://msmvps.com/blogs/audrey/archive/2010/06/10/odata-use-odata-data-with-wcf-data-services-and-silverlight-4.aspx"&gt;http://msmvps.com/blogs/audrey/archive/2010/06/10/odata-use-odata-data-with-wcf-data-services-and-silverlight-4.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;Darrel Miller's Bizcoder blog: World’s simplest OData service&lt;br&gt;
&amp;nbsp;&lt;a href="http://www.bizcoder.com/index.php/2010/03/26/worlds-simplest-odata-service/"&gt;http://www.bizcoder.com/index.php/2010/03/26/worlds-simplest-odata-service/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Once you deploy your OData service to a real web hosting environment, you'll likely
need to do some special setup to access your OData service from Silverlight 4 (clientaccesspolicy.xml
/ crossdomain.xml):
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;Making a Service Available Across Domain Boundaries&lt;br&gt;
&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx"&gt;http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Tremendous thanks go out to &lt;a href="http://www.ignitionpointsolutions.com/Blog/tabid/56/Default.aspx"&gt;Scott
Davis of Ignition Point Solutions&lt;/a&gt; for pointing me to the flawed project setup
as the reason I couldn't get this working initially.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.capprime.com/software_development_weblog/aggbug.ashx?id=4839bf08-5a1b-4b2a-954d-aa90d0f3f979" /&gt;</description>
      <comments>http://www.capprime.com/software_development_weblog/CommentView,guid,4839bf08-5a1b-4b2a-954d-aa90d0f3f979.aspx</comments>
      <category>Knowledge Base</category>
      <category>Visual Studio 2010</category>
      <category>Web Services</category>
      <category>Silverlight</category>
      <category>OData</category>
    </item>
  </channel>
</rss>