Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to Web Services, and I now understand how to pull information from the web service to my console application by adding the web service reference in my console application and calling the web service's methods. But my main goal is to send information to the web service from the the console application. How can this be done? Here is my code so far (calling the methods from the web service).

My 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;
using Soap_Test.aim;
using System.ServiceModel;
using System.Windows.Forms;
using System.Web.Services.Protocols;



namespace Soap_Test
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {

            Service aim = new Service();
            string result = aim.WORD();
            Console.WriteLine(result);
            Console.ReadLine();

                

        }


        }
    }


and my web service....

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


[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 WORD()
    {

        return "Work";
    }

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

        [WebMethod]
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }


    }


Thanks in Advance!
Posted
Comments
Sergey Alexandrovich Kryukov 22-Apr-13 13:22pm    
On the client side, where is the declaration of "Service", what is it?
—SA

1 solution

The question is: in your client code, where did you get the type Service, what is it? Did you add a Web reference?

Anyway, this is a short tutorial: http://www.c-sharpcorner.com/UploadFile/718fc8/consuming-web-service-in-console-application/[^].

—SA
 
Share this answer
 
Comments
Dustin Prevatt 22-Apr-13 13:34pm    
Yes on the client i added the service as a web reference.
Sergey Alexandrovich Kryukov 22-Apr-13 13:36pm    
OK, review the tutorial, try its code out, find out what are you missing...
—SA
Dustin Prevatt 22-Apr-13 13:42pm    
I looked at the tutorial and i am seeing the code from the web service being used within the console app, but i would like to pass a string from the console application to the web service.
Sergey Alexandrovich Kryukov 22-Apr-13 15:37pm    
What difference could it make?
—SA
Dustin Prevatt 22-Apr-13 13:43pm    
Basically i would like to run the console application on a machine and then record the output of the console and store it within the web service. Is this possible?

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