4

我已按照本教程构建我的聊天应用程序。当我尝试添加对我的服务的引用时,我收到以下错误:

合同需要 Duplex,但绑定“BasicHttpBinding”不支持它或未正确配置以支持它。

我的 web.config 如下:

<extensions>
  <bindingExtensions>
    <add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </bindingExtensions>
</extensions>

<bindings>      
  <pollingDuplex>
    <binding name="chatPollingDuplex" duplexMode="MultipleMessagesPerPoll"/>
  </pollingDuplex>
</bindings>    

<services>      
  <service name="PrototypeSite.ChatService">        
    <endpoint address="" binding="pollingDuplex" bindingConfiguration="chatPollingDuplex" contract="PrototypeSite.ChatService" />
    <endpoint address="mex" binding="wsDualHttpBinding" contract="IMetadataExchange"/>
  </service>      
</services>
4

2 回答 2

6

当我遇到这个错误时,这让我很痛苦,但解决方案非常简单——仔细检查你的 web.config 中的服务名称。

无论您在同一个 Web 程序集中是否有服务,都必须包含服务的完整 TypeName

于 2012-02-07T06:54:09.840 回答
1

BasicHttpBinding 是在默认端点上使用的绑定 - 当找不到与服务名称匹配的元素时创建的绑定。元素中的“名称”属性必须与服务类的完全限定名称匹配,我猜您的场景中并非如此。

如果您使用 C#,则完全限定名称将是完整的命名空间 + '.' + 班级名称。如果您使用的是 VB,则项目的“根命名空间”属性可能会附加到命名空间名称之前。找出要使用的名称的可靠方法是使用反射器或 ildasm 等工具并打开包含您的服务类的 DLL。

于 2011-05-15T14:44:59.050 回答