![](/img/trans.png)
[英]RESTful WCF Services with No svc file and No config with parameter binding
[英]WCF .svc worked but not the config file
我正在嘗試使用配置文件來定義端點和服務信息。 我有一個非常簡單的代碼,其中包含 OneWay 服務和 Duplex 服務。 當我沒有嘗試更改配置文件時,OneWay 工作。
現在,我想使用配置文件來定義這兩個服務。
Service1 合同名稱是IOneWayService
,而 Service2 合同名稱是ICallBackService
。
兩者都在各自的具體類名稱OneWayService.svc.cs
和CallBackService.svc.cs
中實現了代碼。
此時的配置文件如下所示:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add relativeAddress="OneWayService.svc" service="TestingWcf.OneWayService"/>
<add relativeAddress="CallBackService.svc" service="TestingWcf.CallBackService"/>
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="TestingWcf.OneWayService">
<endpoint address="http://localhost:60847/One"
binding="wsHttpBinding"
contract="IOneWayService" />
</service>
<service name="TestingWcf.CallBackService">
<endpoint address="http://localhost:60847/Two"
binding="wsHttpBinding"
contract="IDuplexService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
嘗試通過此 url: http://localhost:60847/OneWayService.svc
執行 OneWayService 時,我總是遇到此錯誤
在服務“OneWayService”實施的合同列表中找不到合同名稱“IOneWayService”。
有人知道為什么嗎?
我已經從servinceHostingEnvironment
標記中刪除了multipleSiteBindingsEnabled= true
,並在合同中添加了命名空間,我可以運行 OneWayService。
此外, Duplex 不能綁定到wsHttpBinding
。 我不得不將其更改為NetTcpBinding
。 但是,我在 Duplex 上遇到了另一個錯誤:
找不到配置綁定擴展“system.serviceModel/bindings/NetTcpBinding”。 驗證此綁定擴展是否已在 system.serviceModel/extensions/bindingExtensions 中正確注冊並且拼寫正確。
從這點開始,我又迷路了。
我在綁定名稱中犯了一個錯誤。 我有一個 NetTcpBinding 大寫字母,它確實需要一個小寫字母: netTcpBinding
。 但是,它仍然無法正常工作,現在我有:
不支持協議“net.tcp”。 >.< !!!
好的,這就解釋了——Visual Studio 默認使用內置的 Cassini web 服務器(除非你已經切換到使用IIS Express )——並且該服務器除了普通的 Z80791B3AE7002CB88C246876 之外不支持任何東西
卡西尼不支持 net.tcp 和類似的東西。
您將需要開始使用單獨的 IIS 虛擬目錄並首先啟用所有必要的支持內容(在添加/刪除 Windows 功能對話框中)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.