1

我花了很长时间才弄清楚这一点。我有一个 WCF 服务,我需要向 Silverlight 客户端发送信息,但我需要一个控制台应用程序才能参与其中。谁能给我一个关于我的 Web.Config 应该是什么样子的提示,以指定控制台应用程序可以访问的附加绑定?当我认为我的工作正常时,SL 客户端无法接收任何消息......

这是我当前的 Web.Config:

<?xml version="1.0"?>

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

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

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <!-- Create the polling duplex binding. -->
    <bindings>
      <pollingDuplex>
        <binding name="myPollingDuplex"
                 duplexMode="MultipleMessagesPerPoll">
        </binding>
      </pollingDuplex>
    </bindings>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name ="EdiManager.Web.EdiPubSub">
        <endpoint address=""
                  binding="pollingDuplex"
                  bindingConfiguration="myPollingDuplex"
                  contract="EdiManager.Web.EdiPubSub"
                  />
        <endpoint address="mex" 
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    </system.serviceModel>
</configuration>
4

3 回答 3

1

您是否希望控制台应用程序也参与轮询双工连接?还是您想使用不同的查询-响应绑定?

另外,我注意到您正在使用 AspNetCompatibility 和轮询双工。如果您正在访问会话状态,您将遇到一些性能问题。我写了一篇关于它的简短博客文章,其中引用了包含测试信息的MSDN 博客文章。

简而言之,轮询双工是一个长时间超时的操作。会话状态锁定并且没有其他请求可以继续,直到轮询超时并且在它再次锁定会话状态提供程序的另一个连接之前。

于 2010-11-06T04:34:50.500 回答
1

如果您不需要全双工,只需使用 wsHttpBinding 而不是 mex (或提供更多信息,您想实现什么)。

于 2010-11-05T22:10:55.037 回答
0

我能够通过使用 WCF 服务编辑器编辑配置而不是手动操作来使其工作。显然我在手动编辑配置时犯了一些错误。这是有效的 web.config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

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

    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <!-- Create the polling duplex binding. -->
    <bindings>
      <wsDualHttpBinding>
        <binding name="myDualHttp" />
      </wsDualHttpBinding>
      <pollingDuplex>
        <binding name="myPollingDuplex" duplexMode="MultipleMessagesPerPoll" />
      </pollingDuplex>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="EdiManager.Web.EdiPubSub">
        <endpoint address="Silverlight" binding="pollingDuplex" bindingConfiguration="myPollingDuplex"
          name="Silverlight" contract="EdiManager.Web.EdiPubSub" />
        <endpoint address="Console" binding="wsDualHttpBinding" bindingConfiguration="myDualHttp"
          name="Console" contract="EdiManager.Web.EdiPubSub" />
      </service>
    </services>
    </system.serviceModel>
</configuration>
于 2010-11-08T13:56:25.480 回答