Robert Kaucher
Robert Kaucher

Reputation: 1861

WCF Polling Duplex Binding and Non-Silverlight Clients

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>

Upvotes: 1

Views: 2009

Answers (3)

Erik Noren
Erik Noren

Reputation: 4339

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.

Upvotes: 1

Robert Kaucher
Robert Kaucher

Reputation: 1861

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>

Upvotes: 0

Puhek
Puhek

Reputation: 475

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

Upvotes: 1

Related Questions