简体   繁体   English

WCF.svc 工作但不是配置文件

[英]WCF .svc worked but not the config file

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.我有一个非常简单的代码,其中包含 OneWay 服务和 Duplex 服务。 The OneWay worked when I haven't try to alter the configuration file.当我没有尝试更改配置文件时,OneWay 工作。

Now, I want to use the configuration file to define both service.现在,我想使用配置文件来定义这两个服务。

Service1 contract name is IOneWayService and the Service2 contract name is ICallBackService . Service1 合同名称是IOneWayService ,而 Service2 合同名称是ICallBackService

Both have implemented code in their concrete respective classes name OneWayService.svc.cs and CallBackService.svc.cs .两者都在各自的具体类名称OneWayService.svc.csCallBackService.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尝试通过此 url: http://localhost:60847/OneWayService.svc执行 OneWayService 时,我总是遇到此错误

The contract name 'IOneWayService' could not be found in the list of contracts implemented by the service 'OneWayService'.在服务“OneWayService”实施的合同列表中找不到合同名称“IOneWayService”。

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.我已经从servinceHostingEnvironment标记中删除了multipleSiteBindingsEnabled= true ,并在合同中添加了命名空间,我可以运行 OneWayService。

Also, the Duplex cannot be bound to the wsHttpBinding .此外, Duplex 不能绑定到wsHttpBinding I had to change it to NetTcpBinding .我不得不将其更改为NetTcpBinding But, I had an other error with the Duplex:但是,我在 Duplex 上遇到了另一个错误:

Configuration binding extension 'system.serviceModel/bindings/NetTcpBinding' could not be found.找不到配置绑定扩展“system.serviceModel/bindings/NetTcpBinding”。 Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.验证此绑定扩展是否已在 system.serviceModel/extensions/bindingExtensions 中正确注册并且拼写正确。

From this point, I am lost again.从这点开始,我又迷路了。

Edit 2编辑 2

I did an error in the binding name.我在绑定名称中犯了一个错误。 I had a capital letter for NetTcpBinding and it does require a lowercase: netTcpBinding .我有一个 NetTcpBinding 大写字母,它确实需要一个小写字母: netTcpBinding However, it's still not working, now I have:但是,它仍然无法正常工作,现在我有:

The protocol 'net.tcp' is not supported.不支持协议“net.tcp”。 >.< !!! >.< !!!

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.好的,这就解释了——Visual Studio 默认使用内置的 Cassini web 服务器(除非你已经切换到使用IIS Express )——并且该服务器除了普通的 Z80791B3AE7002CB88C246876 之外不支持任何东西

Cassini doesn't support net.tcp and anything like that.卡西尼不支持 net.tcp 和类似的东西。

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)您将需要开始使用单独的 IIS 虚拟目录并首先启用所有必要的支持内容(在添加/删除 Windows 功能对话框中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM