这是我的代码:
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();
}
}
}
首先,有几个问题:
'baseAddress' 属性究竟是什么?当我使用默认的 F5(无控制台应用程序)启动我的服务时,该服务在 localHost 上的随机端口上启动。我怎样才能写一个确切的数字并期望它去那里?对此一头雾水。
什么是relativeAddress 属性?它说 BankService 但我应该在该属性中写什么?对此也感到困惑。
这是我尝试运行此控制台应用程序时收到的确切错误消息:
HTTP 无法注册 URL http://+:8000/Simple/。您的进程没有对此命名空间的访问权限(有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=70353 )。