Solved

Web Services/Console Application/C#

Posted on 2011-02-24
5
937 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now