Solved

Web Services/Console Application/C#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

28 Experts available now in Live!

Get 1:1 Help Now