2011-05-07 442 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