Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add a web service reference to a console app

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();
                }


            }
        }
like image 344
raklos Avatar asked May 20 '09 13:05

raklos


People also ask

How do I add a web service reference to a web application?

To add a Web Reference You can also open the Add Web Reference dialog box in the Solution Explorer pane by right-clicking References and selecting Add Web Reference. In the Web reference name box, rename the Web reference toExcelWebService. Click Add Reference to add a Web reference for the target Web service.

Can we add web config in console application?

as web. config, but for console and WinForms applications. To add one to your project, right-click the project in Solution Explorer, Add..., New Item... and pick "Application Configuration File" from the Templates box.

How do you add a service reference?

To add a reference to a service in the current solution (. NET Framework projects) In Solution Explorer, right-click the name of the project to which you want to add the service, and then click Add Service Reference. The Add Service Reference dialog box appears.


2 Answers

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".
like image 87
chakra Avatar answered Sep 28 '22 07:09

chakra


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

like image 24
RichardOD Avatar answered Sep 28 '22 05:09

RichardOD