0

这是我的代码:

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

首先,有几个问题:

  1. 'baseAddress' 属性究竟什么?当我使用默认的 F5(无控制台应用程序)启动我的服务时,该服务在 localHost 上的随机端口上启动。我怎样才能写一个确切的数字并期望它去那里?对此一头雾水。

  2. 什么relativeAddress 属性?它说 BankService 但我应该在该属性中写什么?对此也感到困惑。

这是我尝试运行此控制台应用程序时收到的确切错误消息:

HTTP 无法注册 URL http://+:8000/Simple/。您的进程没有对此命名空间的访问权限(有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=70353 )。

4

1 回答 1

0

首先,您的客户项目是否设置为启动项目?

并回答您的问题。

1) baseAddress ( URI Class ) 是您托管服务的基地址。我在想你正在启动其他项目。

2)您有两个配置端点的选项(参考)。相对和绝对。您这样做的方式将占用您的基础并附加您的亲戚-> http://localhost:8000/Simple/BankService

最后要解决您的托管问题,请参阅此 SO 链接:

WCF 服务主机访问权限

于 2010-04-20T13:24:00.143 回答