2011-05-07 112 views
0

我正在尝试构建一个小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 )。

谁能帮我这个

+0

如果您发布代码,XML或数据样本,请**在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码示例”按钮(“{}”)以精确地设置格式和语法突出显示它! – 2011-05-07 12:51:31

+0

最重要的部分 - 服务器端和客户端的** configs **缺失。没有这些,我们只能猜测..... – 2011-05-07 12:52:23

+0

您是否在错误消息中点击了Microsoft链接?它解释了它是什么。 – 2011-05-07 13:21:13

回答

0

你需要运行与提升的权限(即,“系统管理员”)主机应用程序。在Vista/Win7下,只有管理帐户才有权注册套接字侦听器。

+0

@ServiceGuys:非常感谢。它的完成..我几乎从XP切换到Win7后忘了这么做 – Chat 2011-05-07 14:31:54

+0

@Chat:那么,你可以接受答案呢? :) – mthierba 2011-05-07 14:44:15

+0

完成..对不起,我错过了第一名:) – Chat 2011-05-07 15:03:26