Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Web Services/Console Application/C#

Posted on 2011-02-24
5
Medium Priority
?
941 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 2000 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 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