Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to know if it is possible to transfer data from a windows service to either a web service or a wcf service. I have read different article that lead me to think that this might could be done using SOAP. I have never attempted to make 2 applications communicate before so any help is appreciated. Thanks in Advance.

C# console app....

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Net;
using System.Diagnostics;
using System.Configuration.Assemblies;



namespace Soap_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "Dustin";

            Aim.NameRequest request = new Aim.NameRequest();
            Aim.ServiceSoapClient serv = new Aim.ServiceSoapClient();

            Aim.NameResponse test = serv.Name(request);

            return name(test);
           
        }
      

        }
    }


Wcf Service

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://aim.oscautomation.com")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]

public class Service : System.Web.Services.WebService
{
    public Service () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
        
        [WebMethod]
        public string Name()  {      
            return "Name";
        }
    }


Still not completely understanding the whole request part of everything. Thank you so far for your help. Please let me know what I am missing.
Posted
Updated 19-Apr-13 7:59am
v3
Comments
ZurdoDev 19-Apr-13 12:12pm    
Yes, you can connect a windows service to a webservice. In fact a console app, windows forms app, web app, just about anything can call a webservice.

Hello,

You can add a reference to the wcf services from the windows service.
If you're using Visual Studio you can abstract from SOAP protocol, because everything is set for you.

Good luck!
 
Share this answer
 
once you have your service up you can create a project (it could be a web API) that calls it and then send it in REST

If you go for the webApi
add the service to your project, and in the controller inside the method do this:
C#
yourService.yourMethodRequest request = new yourService.yourMethodRequest();
           yourService.ServiceClient serv = new yourService.ServiceClient();

            yourService.yourMethodResponse test = serv.yourMethod(request);

           return View(test);


This will return it like json or XML to be call in REST

if you want to go for the WCF solution read this Reusing WCF Service Across Several Applications using Different Bindings[^]



Hope it helps
 
Share this answer
 
v2
Comments
Dustin Prevatt 19-Apr-13 13:47pm    
Thank You for your reply! Please take a look at my code above. The yourMethodRequest part I am not quite understanding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900