Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6742251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:49:17+00:00 2026-05-26T11:49:17+00:00

Today I am digging into WCF Data Service and I have a question regarding

  • 0

Today I am digging into WCF Data Service and I have a question regarding this. Can I create WCF Data service as Library and just only create WCF data Service in our existing web app and take reference that library using Factory property so service will deploy with existing web application.

As I know We can create WCF Service Library and only need to take reference that library in Web application like :

  1. Create a WCF Library and implement service contract
  2. Create a Web application and add new item as Wcf service file then take reference WCF library

    <%@ ServiceHost Service=”MyServiceLibrary.MyService” Factory=”System.ServiceModel.Activation.WebServiceHostFactory” />

Instead of a service library, I want to create OData service library.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:49:17+00:00Added an answer on May 26, 2026 at 11:49 am

    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.

    Here’s how:

    • put your data model (EF Data Model) into its own assembly, let’s call it DataModel

    • create a new class library project (call it MyDataServiceHost)

    • add a few references:

      • your DataModel assembly with the data layer
      • System.ServiceModel
      • System.ServiceModel.Web
      • System.Data.Services.Client
      • System.Data.Services – you cannot pick this from the usual Add Reference dialog under the .NET category – you need to browse for the assembly file. Find the directory C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 (or C:\Program Files (x86)\... on a 64-bit machine) and pick the System.Data.Services.dll inside it
    • add a new class to that class library and call it e.g. YourDataService.cs – it will look something like this:

      using System.Data.Services;
      using System.Data.Services.Common;
      
      using DataModel;
      
      namespace MyDataServiceHost
      {
          public class YourDataService : DataService<YourModelEntities>
          {
              // 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;
              }
          }
      }
      

      You can name the class anything you like, and it has to derive from DataService<T> where T 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 (database)Entities or whatever you picked when you created the EDM

    • add another class to your new project, call it MyDataServiceHost.cs and it will look something like this:

      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();
                  }
              }
          }
      }
      

      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.

    • now you can start up your WCF Data Service from any app using:

      MyDataServiceHost.LaunchDataService("http://localhost:4444/YourService");
      
    • last thing to remember: the app that you use to launch the WCF Data Service must have 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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, I ran into this weird problem with a user using Mac OS X.
Today somebody told me that interface implementation in C# is just Can-Do relationship, not
Today I just opened the project I was working on XCODE 4, and only
Today I was digging with TPL and found a new class Task.Now I just
This is probably a pretty basic question, but just something that I wanted to
Today my problem is this I have 2 columns and I wish to check
today I have a quick question. Here is my function: function checkheight() { var
Today, I have come across a bug in my Zend Framework application. This is
Today we have received some strange exceptions on our production website. They all have
today i tested the geolocation system implement by google on Chrome, with this page:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.