Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, you can host a WCF Data Service in your own assembly - with a few little tricks. I researched this a while ago and came up with these steps / instructions.</p> <p>Here's how:</p> <ul> <li><p>put your data model (EF Data Model) into its own assembly, let's call it <code>DataModel</code></p></li> <li><p>create a new class library project (call it <code>MyDataServiceHost</code>)</p></li> <li><p>add a few references:</p> <ul> <li>your <code>DataModel</code> assembly with the data layer</li> <li><code>System.ServiceModel</code></li> <li><code>System.ServiceModel.Web</code></li> <li><code>System.Data.Services.Client</code></li> <li><code>System.Data.Services</code> - you cannot pick this from the usual <code>Add Reference</code> dialog under the .NET category - you need to browse for the assembly file. Find the directory <code>C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0</code> (or <code>C:\Program Files (x86)\...</code> on a 64-bit machine) and pick the <code>System.Data.Services.dll</code> inside it</li> </ul></li> <li><p>add a new class to that class library and call it e.g. <code>YourDataService.cs</code> - it will look something like this:</p> <pre><code>using System.Data.Services; using System.Data.Services.Common; using DataModel; namespace MyDataServiceHost { public class YourDataService : DataService&lt;YourModelEntities&gt; { // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } } } </code></pre> <p>You can name the class anything you like, and it has to derive from <code>DataService&lt;T&gt;</code> where <code>T</code> is the name of your data model; if you're using Entity Framework, it's the name of your object context class - typically something like <code>(database)Entities</code> or whatever you picked when you created the EDM</p></li> <li><p>add another class to your new project, call it <code>MyDataServiceHost.cs</code> and it will look something like this:</p> <pre><code>using System; using System.Data.Services; using DataModel; namespace MyDataServiceHost { public class MyDataServiceHost { public static void LaunchDataService(string baseAddress) { Uri[] baseAddresses = new Uri[1]; baseAddresses[0] = new Uri(baseAddress); using(DataServiceHost host = new DataServiceHost(typeof(YourDataService), baseAddresses)) { host.Open(); Console.WriteLine("DataService up and running....."); Console.ReadLine(); host.Close(); } } } } </code></pre> <p>It instantiates a DataServiceHost, which is derived from WebServiceHost (which in turn is derived from ServiceHost) and it will spin up the WCF Data Service runtime for you.</p></li> <li><p>now you can start up your WCF Data Service from any app using:</p> <pre><code>MyDataServiceHost.LaunchDataService("http://localhost:4444/YourService"); </code></pre></li> <li><p>last thing to remember: the app that you use to launch the WCF Data Service <strong>must have</strong> the connection string (the EDM connection string, if you're using Entity Framework) in its app.config (or web.config) in order for this to work!</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload