2011-11-03 63 views
6

我對城堡wcf設施註冊感到困惑。我是否需要svc文件來爲非HTTP服務設置Castle Wcf Facility

我閱讀了一些BasicHttpBinding的博客文章。 但找不到一個清晰簡單的示例來設置net.tcp設置。

我想從一個控制檯應用程序託管服務...

我寫了這樣的事......你可以在這裏看到了問題?

_container = new WindsorContainer(); 
_container.AddFacility<WcfFacility>(); 

_container.Register(Component.For<IMembershipService>().ImplementedBy<MembershipService>() 
    .AsWcfService(
     new DefaultServiceModel() 
      .AddEndpoints(WcfEndpoint 
        .BoundTo(new NetTcpBinding() { PortSharingEnabled = false }) 
        .At("net.tcp://localhost/MembershipService") 
      ) 
      .PublishMetadata() 
    ) 
); 

回答

4

如果你想要發佈元數據,你將需要啓用端口共享(讓MEX端點共享同一端口作爲常規TCP端口 - 如果你有此設置爲false,你會得到一個AddressAlreadyInUse例外),你可能需要指定一個端口上的網址(不知道TCP否則將使用什麼端口),所以你的代碼應該(假設端口8080是確定你):

_container.Register(Component.For<IMembershipService>().ImplementedBy<MembershipService>() 
    .AsWcfService(
     new DefaultServiceModel() 
      .AddEndpoints(WcfEndpoint 
        .BoundTo(new NetTcpBinding() { PortSharingEnabled = true}) 
        .At("net.tcp://localhost:8080/MembershipService") 
      ) 
      .PublishMetadata() 
    ) 
); 

這正常使用的城堡溫莎3.0。

+0

請記住不允許用戶使用端口共享的可能性。我有這個問題,我得到了一個CommunicationException,提示我可以編輯文件SMSvcHost.exe.config中的allowAccounts節以使用戶可以這樣做。但是這個解決方案不可行,因爲這個文件位於C:\ Windows \ Microsoft.NET \ ...我的解決方案到目前爲止:刪除Mex Endpoint/PublishMetadata()。如果將來需要,我將用第二種綁定配置發佈元數據。 –

+0

哦,之前我的Windows服務中禁用了「Net.Tcp端口共享服務」。您的最終用戶也可能會禁用此功能,並且可能無法啓用它(並且使用安裝程序啓用它不是一個好選擇) –

相關問題