views:

914

answers:

3

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


            }
        }
A: 

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

RichardOD
thanks that helped
raklos
Glad I could help.
RichardOD
A: 

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.

Marc Gravell
Hi Marc,I did what you said andi pointed address to: http://localhost:9090/PersonService and it gives this error:There was an error downloading 'http://localhost:9090/PersonService'.The request failed with HTTP status 400: Bad Request.Metadata contains a reference that cannot be resolved: 'http://localhost:9090/PersonService'.Metadata contains a reference that cannot be resolved: 'http://localhost:9090/PersonService'.If the service is defined in the current solution, try building the solution and adding the service reference again.
raklos
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.
Marc Gravell
when i point to http://localhost:9090/PersonService whilst the service is running it gives a page not found.
raklos
A: 

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

Wayne Hartman