WCF 轮询双工绑定和非 Silverlight 客户端

发布于 2024-10-01 00:42:43 字数 2408 浏览 5 评论 0原文

我花了很长时间才弄清楚这个问题。我有一个 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>

I'm having a heck of a time figuring this out. I have a WCF service that I need to puch information to Silverlight client, but I need a console application to also be able to participate in this. Could anyone give me a hint on to what my Web.Config should look like to specify an additional binding that the console app could access? When I think I get things working the SL clients are unable to receive any messages...

Here is my current 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简美 2024-10-08 00:42:43

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

If you don't need full duplex just use wsHttpBinding instead of mex (or provide more info what would you like to achieve).

远山浅 2024-10-08 00:42:43

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

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

简而言之,轮询双工是一个长时间超时的操作。会话状态会锁定,并且在轮询超时之前以及在建立另一个连接再次锁定会话状态提供程序之前,其他请求都无法继续。

Do you want the console application to also participate in the polling duplex connection? Or will you want to use a different query-response binding?

Also, I notice that you're using AspNetCompatibility with polling duplex. If you're accessing session state you will experience some performance issues. I did a short blog post about it which references an MSDN blog post with testing information.

In short, the polling duplex is a long-timeout operation. The session state locks and no other requests can proceed until the poll times out and before it makes another connection that locks the session state provider again.

何其悲哀 2024-10-08 00:42:43

我能够通过使用 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>

I was able to get it working by editing the config with the WCF Service editor and not doing it by hand. Clearly I was making some mistake editing the config manually. Here is the web.config that works:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文