Solved

Web Services/Console Application/C#

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

17 Experts available now in Live!

Get 1:1 Help Now