views:

89

answers:

1

Here's my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using BankServiceClient.BankServiceReference;

namespace BankServiceClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8000/Simple");
            Type instanceType = typeof(BankServiceReference.BankClient);
            ServiceHost host = new ServiceHost(instanceType,baseAddress);

            using (host)
            {
                Type contractType = typeof(BankServiceReference.IBank);
                string relativeAddress = "BankService";
                host.AddServiceEndpoint(contractType, new BasicHttpBinding(), relativeAddress);

                host.Open();

                Console.WriteLine("Press <ENTER> to quit.");
                Console.ReadLine();

                host.Close();
            }

            /*
             * Consuming a WCF Service and using its method.
             */

            //IBank proxy = new BankClient();

            //double number = proxy.GetBalance(1234);

            //Console.WriteLine(number.ToString());
            //Console.ReadLine();
        }
    }
}

First, a couple of questions:

  1. The 'baseAddress' attribute, what exactly is it? When I launched my service using the default F5 (no console application) the service launched on a random port on localHost. How can I write in an exact number and expect it to go there? Confused at this one.

  2. What is the relativeAddress attribute? It says BankService but what should I write in that attribute? Confused at this one as well.

Here's the exact error message I get when I try to run this Console application:

HTTP could not register URL http://+:8000/Simple/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).

A: 

First is your client project set to be the start up project?

And to answer your questions.

1) baseAddress (URI Class) is the base address for your hosted service. I am thinking you are launching some other project.

2) You have two options on configuring endpoints(reference). Relative and Absolute. The way you did it will take your base and appends your relative -> http://localhost:8000/Simple/BankService

Lastly to fix your hosting issue see this SO link:

http://stackoverflow.com/questions/885744/wcf-servicehost-access-rights

Nix