WCF .svc 有效,但配置文件无效
我正在尝试使用配置文件来定义端点和服务信息。我有一个非常简单的代码,其中包含 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>
当尝试通过以下网址执行 OneWayService 时,我总是遇到此错误:http://localhost:60847/OneWayService.svc
合约名称“IOneWayService” 在列表中找不到 服务执行的合同 “OneWayService”。
有人知道为什么吗?
编辑
我已从 servinceHostingEnvironment
标记中删除了 multipleSiteBindingsEnabled= true
,并在合同中添加了命名空间,我可以运行 OneWayService。
此外,Duplex 无法绑定到 wsHttpBinding
。我必须将其更改为 NetTcpBinding。但是,我在 Duplex 上遇到了另一个错误:
配置绑定扩展 'system.serviceModel/绑定/NetTcpBinding' 找不到。验证这 绑定扩展正确 注册于 system.serviceModel/扩展/bindingExtensions 并且拼写正确。
从这一刻起,我又迷失了。
编辑2
我在绑定名称中犯了一个错误。我的 NetTcpBinding 是大写字母,但它确实需要小写字母:netTcpBinding
。但是,它仍然不起作用,现在我有:
协议“net.tcp”不是 支持。 >。< !!!
I am trying to use the configuration file to define endpoint and services information. I have a very simple code that contain OneWay service and a Duplex service. The OneWay worked when I haven't try to alter the configuration file.
Now, I want to use the configuration file to define both service.
Service1 contract name is IOneWayService
and the Service2 contract name is ICallBackService
.
Both have implemented code in their concrete respective classes name OneWayService.svc.cs
and CallBackService.svc.cs
.
The configuration file at this moment look like that :
<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>
I always have this error when trying to execute the OneWayService via this url : http://localhost:60847/OneWayService.svc
The contract name 'IOneWayService'
could not be found in the list of
contracts implemented by the service
'OneWayService'.
Anybody have an idea why?
Edit
I have removed the multipleSiteBindingsEnabled= true
from the servinceHostingEnvironment
tag and in the contract added the namespace and I could runt the OneWayService.
Also, the Duplex cannot be bound to the wsHttpBinding
. I had to change it to NetTcpBinding
. But, I had an other error with the Duplex :
Configuration binding extension
'system.serviceModel/bindings/NetTcpBinding'
could not be found. Verify that this
binding extension is properly
registered in
system.serviceModel/extensions/bindingExtensions
and that it is spelled correctly.
From this point, I am lost again.
Edit 2
I did an error in the binding name. I had a capital letter for NetTcpBinding and it does require a lowercase: netTcpBinding
. However, it's still not working, now I have:
The protocol 'net.tcp' is not
supported. >.< !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这解释了 - Visual Studio 默认使用内置的 Cassini Web 服务器(除非您已经切换到使用 IIS Express) - 该服务器除了普通 http 之外不支持任何内容。
卡西尼号不支持 net.tcp 和类似的东西。
您将需要开始使用单独的 IIS 虚拟目录,并首先启用所有必要的支持内容(在“添加/删除 Windows 功能”对话框中)
OK, that explains it - Visual Studio by default uses the built-in Cassini web server (unless you've already switched to using IIS Express) - and that server doesn't support anything but plain http.
Cassini doesn't support net.tcp and anything like that.
You will need to start using a separate IIS virtual directory and first enable all the necessary support stuff (in the Add/remove Windows Features dialog)