locked
Consume Windows Service In Web Application? RRS feed

  • Question

  • HI All,

    Am Developing Web App Which collects some data from user and i need to store these data in DB.

    Parallel to this i have a Stand Alone application which dose the same. I have windows service which handles Insertion of user Input to database.

    Now i need to use the same "Insert()" from windows service from my web application.

    Any suggestion would be of great Help

    Thanks 


    Arjun

    Tuesday, August 4, 2015 1:55 PM

Answers

  • Hi ArjunShrivatsa,

    I suggest you can refer to the following articles:

    1.how to call window service method into web application

    http://forums.asp.net/t/1677902.aspx?how+to+call+window+service+method+into+web+application

    2.how to access remote computer windows service using asp.net

    http://stackoverflow.com/questions/4489541/how-to-access-remote-computer-windows-service-using-asp-net

    3.windows service cannot access a webservice

    http://stackoverflow.com/questions/2753813/windows-service-cannot-access-a-webservice

    Best Regards,

    Vince Li

    • Marked as answer by Grady_Dong Monday, August 17, 2015 2:10 AM
    Thursday, August 13, 2015 8:33 AM

All replies

  • Possible approaches.

    1. Duplicate your code between your windows service and web app.
      - This creates for dubbel code, dubbel test, dubbel changes when change requests come in, etc. 
      + You can update each app independently
    2. Create a common/shared library (a .dll in vs2013 or shared code in vs2015) and each code base can use that library and have your insert logic here
      + single location for changes, single contract
      - if you update the shared code for one app you probably have to update the other as they are tied to eachother
    3. Create a stored proc in the db and put your logic here, call this proc from your service and also your web api.
      + all changes should occur in the database in your stored procedure in a single location
      - changing the stored procedure also requires you to possible push out changes in both applications
    4. Expose endpoints on the service using WCF or Remoting and have the web app call it to execute the insert on its behalf.
      + all changes to insert logic can be maintained in a single location
      - changes to the contract interface require changes in both application
      - calls traversing process boundaries or even machine boundaries if the service is not on the same machine are much more expensive and will possibly slow down the response to the insert request

    Mark as answer or vote as helpful if you find it useful | Igor

    Tuesday, August 4, 2015 2:06 PM
  • Now i need to use the same "Insert()" from windows service from my web application.

    Make a classlib project call it DAL (Data Access Layer) for data persistence with your code  and set reference to the DAL DLL in the Windows service and the Web application.

    You can use the repository, Data Access Object, or Unit Of Work pattern in the DAL, or just take your existing code and place it in the DAL.  

    It's called Separation of Concerns.

    https://en.wikipedia.org/wiki/Separation_of_concerns

    Tuesday, August 4, 2015 3:07 PM
  • Sparco & DA924

    Thanks For your Reply,

    Problem is It's not only one method in in my Service Its Bunch of Methods which i'll be calling as and when needed. and this Windows services has got huge code in it.

    All i need to do is Just to use the same methods rather than copying that methods in  DAL or any shared library.

    I cannot follow this approach because it takes ages to copy that code to Shared project.

    Thanks

    Arjun.M

     

    Arjun

    Wednesday, August 5, 2015 4:43 AM
  • Hi ArjunShrivatsa,

    I suggest you can refer to the following articles:

    1.how to call window service method into web application

    http://forums.asp.net/t/1677902.aspx?how+to+call+window+service+method+into+web+application

    2.how to access remote computer windows service using asp.net

    http://stackoverflow.com/questions/4489541/how-to-access-remote-computer-windows-service-using-asp-net

    3.windows service cannot access a webservice

    http://stackoverflow.com/questions/2753813/windows-service-cannot-access-a-webservice

    Best Regards,

    Vince Li

    • Marked as answer by Grady_Dong Monday, August 17, 2015 2:10 AM
    Thursday, August 13, 2015 8:33 AM