获取错误:合同需要Duplex,但Binding'BasicHttpBinding'不支持它,或者没有正确配置以支持它

ass*_*fmo 8 c# silverlight wcf duplex wcf-binding

我有一个WCF服务和一个Silverlight 5客户端.我已经定义了以下接口:

[ServiceContract(Namespace = "Silverlight", CallbackContract = typeof(IDuplexClient))]
public interface IDuplexService
{
    [OperationContract]
    void Subscribe(string userId);

    [OperationContract]
    void Unsubscribe(string userId);
}

[ServiceContract]
public interface IDuplexClient
{
    [OperationContract(IsOneWay = true)]
    void PushNotification(string msg);
}
Run Code Online (Sandbox Code Playgroud)

这是我的Web.config文件:

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

当我尝试运行服务时,我得到:

由于编译期间发生异常,无法激活服务'/ServerService.svc'.异常消息是:Contract需要Duplex,但Binding'BasicHttpBinding'不支持它,或者没有正确配置以支持它.

我知道我需要为Web.config添加一些属性,但无论我在哪里(以及我尝试过的任何东西)都无法使其工作.

我是WCF的新手,我希望你对这个问题有所帮助.我所有的谷歌搜索引导我无处可回答在这里问同样问题的人的答案对我不起作用.

所以我决定放弃搜索,然后问一下.

更新:我使用此链接创建界面 - http://msdn.microsoft.com/en-us/library/cc645027%28v=vs.95%29.aspx

com*_*ech 16

如果这是WCF的web.config配置的范围,那么你就错过了 定义合同的部分:

<services>
  <service name="WebApplication1.Service1">
    <endpoint address="" binding="wsDualHttpBinding" contract="WebApplication1.IService1" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
Run Code Online (Sandbox Code Playgroud)

如果您确实指定了此部分,另一个可能的原因是合同名称不是完全合格的; 它必须包含完整的命名空间,而不仅仅是合同的名称.

以下是完整的System.ServiceModel配置:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WebApplication1.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WebApplication1.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,应用程序命名空间是WebApplication1,服务的类名是Service1(即Service1.svc),Service1实现的接口是IService1.

  • 好消息!我已经更新了答案,以防其他人遇到这种情况. (2认同)