Solved

Web Services/Console Application/C#

Posted on 2011-02-24
5
939 Views
Last Modified: 2013-12-17
Hello Experts,

I was wondering if you could give me a little help. I have created a project with 2 applications in it. One is aN ASP.NET Web Service, called "FindSum1" and the second is a Console Application called "FindSum2".

Within "FindSum1" I created a web method with the following code attached bellow.

I then created "FindSum2" which as previously stated was a Console Application. After that i connected the project via WebService and named it "AddService".

Within the console file I would like to have the user input 5 different integers and it will use the webservice to add them all up and return the answer of the sum. Any help with how I go about this? I know how to do this in the traditional method, but I have became a little lost when it comes to calling the web service. I have also attached the code that I have implemented so far for the Console Application.

This is the code I have so far. Any help would be GREATLY appreciated!

Thanks in advance!
           


[WebMethod]
        public int Add(int a, int b, int c, int d, int e)
        {
            return a + b + c + d + e;
        }

Open in new window

namespace FindSum2
{
    class Program
    {
        static void Main(string[] args)
        {
                AddService.Service1SoapClient client = new AddService.Service1SoapClient();
Console.Write("Please Enter Integer 1: ");

      }
    }
}

Open in new window

0
Comment
Question by:04004756
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:quizwedge
ID: 34976542
Assuming the class name of your WebMethod is called FindSum1, the following code should work:

FindSum1.FindSum1 myWebService;
Console.Write(myWebService.Add(1, 2, 3, 4, 5);

Open in new window

0
 

Author Comment

by:04004756
ID: 34976563
Thanks for the reply. I had code similar to this and it worked. When I run the console, rather than having pre determined numbers , the console would ask the user to input five numbers instead, and that would take them, add them up and display the result.

Sorry if I had originally confused you. Thanks for the help so far.
0
 
LVL 14

Expert Comment

by:quizwedge
ID: 34976643
If I understand correctly, you have the web service working, but you need to know how to get input for a console application?

If that's the case, check out http://social.msdn.microsoft.com/Forums/en/vblanguage/thread/c9410e6c-4462-45aa-8172-af12c07b48f9

You can save each ReadLine to a string and then call the webservice using CInt(ReadLine1), CInt(ReadLine2), etc.
0
 

Author Comment

by:04004756
ID: 34976679
Yeah, I have the web service working 100percent correct. I know in a normal application you would type:-

static void Main(string[] args)
    {
      // Storage
      int value1 = 0;
      int value2 = 0;
      int total = 0;

      // Get first number
      Console.Write("Enter a whole number: ");
      value1 = System.Convert.ToInt32(Console.ReadLine());

      // Get second number
      Console.Write("Enter another whole number: ");
      value2 = System.Convert.ToInt32(Console.ReadLine());

      // Add them together
      total = value1 + value2;

      // Output the answer
      Console.WriteLine("The total is {0}", total);
    }

etc. etc. to read in values from the user and to add them all up. I'm just not too sure how to edit that to fit into the web service.
0
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 34976855
Not sure how far you've gotten with setting it up in your console app, so I'll start from the beginning.

1.  In Visual Studio, right click your Console App and select Add Web Reference.
2.  Enter the URL of your Web Service.
3.  Hit "Go"
4.  Under "Web Reference Name"
5.  Hit "Add Reference"
6.  In your console app, add the following code. Note, I'm assuming the class name of your web service is FindSum1

FindSum1.FindSum1 myWebService;
Console.Write("The total is {0}", myWebService.Add((int)value1, (int)value2, (int)value3, (int)value4, (int)value5));

Open in new window


You read in value1, etc. as you have in your normal application code.

0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question