Search code examples
wcfwindows-serviceswcf-ria-services

use of RIA Service project's DLL in Window service


I have one project which has RIAService with entity framework that is referenced to my Silvelright project. so when i build project that build RIA Service project's DLL and put that in Bin/Debug folder of Silverlight project.

Domain service function is like below

[EnableClientAccess()]
public partial class MyClassDomainService : LinqToEntitiesDomainService<MyDatabaseEntities>
{
    [Invoke]
    public void MyFunction(int Para1, string Para2, int Para3, string Para4)
    {
          //mycode
    }
}

Now i am build this porject and copy this RIAService.dll and other require DLLs to my another project is window service project.

Now in window service i am creating object of this Domain service as like below in timerQlinkRequest_Elapsed() function.

private void timerQ_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    try
    {
        MyClassDomainContext objcontext = new MyClassDomainContext();
        objcontext.MyFunction(1, "ADD", 1234, "Vehicle");
    }
    catch (Exception ex)
    {
        LogMessage("Error : StackTrace : " + ex.StackTrace);
    }
}

After installing and Start window service i get below error in ex.stackTrace in log filem as below

Error : StackTrace :    at MS.Internal.JoltHelper.get_Context()
   at MS.Internal.XcpImports.Application_GetCurrent(IntPtr& pApp)
   at System.Windows.Application.get_Current()
   at System.ServiceModel.DomainServices.Client.WebDomainClient`1.ComposeAbsoluteServiceUri()
   at System.ServiceModel.DomainServices.Client.WebDomainClient`1..ctor(Uri serviceUri)
   at RIAService.Web.Service.QLink.MyClassDomainContext..ctor()
   at MywindowService.MyService1.timerQ_Elapsed(Object sender, ElapsedEventArgs e)

so my main confusion is, can i do like this? if yes then where i go wrong?

please help me.

waiting for reply.


Solution

  • i get solution in other way,

    in my project.Web (ASP.NET project) i create a simple WCF application that call my function of WCF RIA Service.

    And in window service solution I add service reference of that WCF service and calling that WCF function and complete my task.

    @duluca thanks fro the reply.