【问题标题】:WCF .svc worked but not the config fileWCF .svc 工作但不是配置文件
【发布时间】:2011-08-31 07:17:05
【问题描述】:

我正在尝试使用配置文件来定义端点和服务信息。我有一个非常简单的代码,其中包含 OneWay 服务和 Duplex 服务。当我没有尝试更改配置文件时,OneWay 工作。

现在,我想使用配置文件来定义这两个服务。

Service1 合约名称为IOneWayService,Service2 合约名称为ICallBackService

两者都在各自的具体类名称OneWayService.svc.csCallBackService.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 执行 OneWayService 时总是出现此错误:http://localhost:60847/OneWayService.svc

合同名称“IOneWayService” 在列表中找不到 服务执行的合同 'OneWayService'。

有人知道为什么吗?

编辑

我已从 servinceHostingEnvironment 标记中删除了 multipleSiteBindingsEnabled= true,并在合同中添加了命名空间,我可以运行 OneWayService。

此外,双工不能绑定到wsHttpBinding。我不得不将其更改为NetTcpBinding。但是,我在使用 Duplex 时遇到了另一个错误:

配置绑定扩展 'system.serviceModel/bindings/NetTcpBinding' 找不到。验证这 绑定扩展是正确的 注册于 system.serviceModel/extensions/bindingExtensions 并且拼写正确。

从此,我又迷路了。

编辑 2

我在绑定名称中犯了一个错误。我有一个 NetTcpBinding 的大写字母,它确实需要小写:netTcpBinding。但是,它仍然无法正常工作,现在我有:

协议“net.tcp”不是 支持的。 >.

【问题讨论】:

  • 您是在 IIS 中托管它(哪个版本??),还是自托管(在例如 Windows NT 服务中)??

标签: c# wcf .net-4.0


【解决方案1】:

好的,这就解释了——Visual Studio 默认使用内置的 Cassini Web 服务器(除非你已经切换到使用 IIS Express)——而且该服务器只支持普通的 http。

Cassini 不支持 net.tcp 和类似的东西。

您需要开始使用单独的 IIS 虚拟目录并首先启用所有必要的支持内容(在“添加/删除 Windows 功能”对话框中)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    相关资源
    最近更新 更多