add a web service reference to a console app

how to call web service in c# console application
how to add web reference in c# console application
how to call console application from web application with parameters
web service console
how to add service reference in c#
c# consume soap web service example
how to add reference in c# console application
how to use service reference in c#

Im creating a simple web service in a console app. (PersonService) this is my Program.cs below

im trying to add a service reference to a different console app (PersonClient) how can i do this? i tried adding it by right clicking, add service reference, pointing to the refernce etc... but it wont work.

        [DataContract]
        public class Person
        {
            [DataMember]
            public string FirstName { get; set; }

            [DataMember]
            public string LastName { get; set; }

        }

        [ServiceContract]
        public interface IPersonLookup
        {
            [OperationContract]
            Person GetPerson(int identifier);
        }

        public class PersonService : IPersonLookup
        {
            public PersonService()
            {
            }
            public Person GetPerson(int identifier)
            {
                Person p = new Person();
                p.FirstName="Jane";
                p.LastName="Doe";
                return p;
            }



        }


        class Program
        {
            static void Main(string[] args)
            {
                using (ServiceHost host = new ServiceHost(typeof(PersonService)))
                {
                    WSHttpBinding binding = new WSHttpBinding();
                    host.AddServiceEndpoint(typeof(IPersonLookup), binding, "http://localhost:9090/PersonService");
                    host.Open();
                    Console.WriteLine("Listening....");
                    Console.ReadLine();
                }


            }
        }

You need to read about WCF MEX Endpoints. Here's a blog post that may help.

[Solved] How to add service reference in the console application , How do I add a service reference in console application? Right click your asmx file in Visual Studio and select "View in browser". That will start the web service project and launch it in a browser, that will ensure it is running so you can add a reference to it. Copy the url from the browser and in your console app add a web reference\service reference to that url.

Solution:

  1. Create a console application using visual studio.
  2. Right click on the project and click on "Add Service Reference...".
  3. On the window, you will find the "Advanced" button at the bottom.
  4. Click on the button and it will open service reference settings window. It has a button at bottom called "Add Web Reference".

Step 2 Adding a Web Reference, How do I add a reference to a Web service? How to Access a Web Service in Console Application. Step 1 : Create a Web application and add a Web Service with some code in it. Create a web application named "WebApplication1". Create a Web Step 2: Create a Console application and add a reference of the Web Service to it. Add a new project

You have two console exes, one which runs a ServiceHost - is that correct? Run the server console without debugging; then in the IDE add the WCF reference to the url. It should work, but it needs the server (your second console exe) to be running when you query the mex.

Consume a Custom WCF Service in a Console Application, How do I add a WCF service reference to the console application? Consuming web service in console application. Create new project. Select ASP.NET Empty Web Application. Give name to your project and click ok button. Go to Solution Explorer and right click at your project. Select Add New Item and select Web Service application. Give it name and click ok button.

When you added the webservice reference, you defined the namespace and 'class name' for the service. You must either add the namespace reference ("using FooNameSpace;") or use the fully qualified class name of the service ("FooNameSpace.BarClass ws = new FooNameSapce.BarClass()");

Consuming web service in console application, URL and then click on Go button. Enter the proper name for the Namespace. The Connected Services page appears as shown in the following image: On the Connected Services page, click Microsoft WCF Web Service Reference Provider. This brings up the Configure WCF Web Service Reference wizard: Select a service. 3a. There are several services search options available within the Configure WCF Web Service Reference wizard:

How to Access a Web Service in Console Application, How do you call a console application from a Web application with parameters? Create a new Console Application in your solution Right click your project and select Add > Service Reference… Rename the namespace if you wish: Click on the Advanced button.

Adding a Web Reference to AppFxWebService.asmx, That should be easy. Refer - Call (Consume) Web Service (ASMX) in Console application using C# and VB.Net[^]. If you look closely, though, you’ll see at the top of the dialog it says “Filtered to: .NET Framework 4 Client Profile”. That’s the issue. Now, if you really are doing HTTP requests in a console application in .NET 4, then I recommend you use the System.Net.HttpWebRequest type that *is* available in the Client profile.

A tutorial on how to add the web service reference (proxy class) to , Consuming web service in console application. Create new project. Select ASP.NET Empty Web Application. Give name to your project and click ok button. Go to Solution Explorer and right click at your project. Select Add New Item and select Web Service application. Give it name and click ok button. This page also enables you to test different Web service methods. Consume a Web Service. Open Visual Studio .NET. Under Project types click Visual C# Projects, then click Console Application under Templates. Add a reference for the MathService Web service to the new console application. This step creates a proxy class on the client computer.

Add WCF Web Service Reference, Create a console application and add a reference of a Web Service to it. Write some code in the console application for calling the web method  In the middle pane, choose Console App (.NET Core). Then name the file Calculator. Add a workload (optional) If you don't see the Console App (.NET Core) project template, you can get it by adding the .NET Core cross-platform development workload. Here's how. Option 1: Use the New Project dialog box

Comments
  • Hi Marc, I did what you said and i pointed address to: localhost:9090/PersonService and it gives this error: There was an error downloading 'localhost:9090/PersonService'. The request failed with HTTP status 400: Bad Request. Metadata contains a reference that cannot be resolved: 'localhost:9090/PersonService'. Metadata contains a reference that cannot be resolved: 'localhost:9090/PersonService'. If the service is defined in the current solution, try building the solution and adding the service reference again.
  • When it is running, try browsing to the service uri in your web-browser. It may give you the service page that tells you how to set up mex; I can't remember off the top of my head, though.
  • when i point to localhost:9090/PersonService whilst the service is running it gives a page not found.