我正在尝试构建一个小WCF服务并希望在测试应用程序中使用它。WCF服务创建
PFB服务代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace HelloIndigo
{
[ServiceContract(Namespace="http://www.thatindigoirl.com/samples/2006/06")]
public interface IHelloIndigoService
{
[OperationContract]
string HelloIndigo();
}
public class HelloIndigoService : IHelloIndigoService
{
public string HelloIndigo()
{
return "Hello indigo";
}
}
}
主机代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri("http://localhost:8000/HelloIndigo")))
{
host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new BasicHttpBinding(), @"HelloIndigoService");
host.Open();
Console.WriteLine("Press <ENTER> to terminate the service hosy");
Console.ReadLine();
}
}
}
}
每当我试图运行主机我得到下面提到的错误host.Open()语句。
HTTP无法注册URL http://+:8000/HelloIndigo/。您的 进程无权访问此名称空间的 (有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=70353 )。
谁能帮我这个
如果您发布代码,XML或数据样本,请**在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码示例”按钮(“{}”)以精确地设置格式和语法突出显示它! – 2011-05-07 12:51:31
最重要的部分 - 服务器端和客户端的** configs **缺失。没有这些,我们只能猜测..... – 2011-05-07 12:52:23
您是否在错误消息中点击了Microsoft链接?它解释了它是什么。 – 2011-05-07 13:21:13