Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Duplex Communication with WCF in Silverlight 4 (Silverlight TV #34)

Download

Right click “Save as…”

In this episode, Tomasz Janczuk of the Silverlight Web Services team joins John to demonstrate how to implement duplex communication with WCF in Silverlight. Tomasz discusses a how to implement a chat application using WCF, the basics of the polling duplex protocol, when the Net.tcp protocol is ideal, and some performance and scalability considerations.

 

 

Relevant links:

Follow us on Twitter @SilverlightTV or on the web at http://silverlight.tv/

 

Tags:

Follow the Discussion

  • Hi Guys,

    A question regarding the web services and Silverlight. Would you be able to shed some light on why there is no support for WSHttpBinding in Silverlight please?

     

    Thank you,

    Yosh

  • Yosh, 

    Silverlight supports a good subset of BasicHttpBinding functionality. The major value add of WSHttpBinding over BasicHttpBinding is supoport for WS-Security and WS-ReliableMessaging. Given substantial demand, we are looking into enabling a subset of WS-Security capabilities in the future release of Silverlight. 

    Thanks,

    Tomasz Janczuk

  • Thank you for the quick reply Thomasz. I work for a law enforcement agency and we were looking at creating a Silverlight application for the patrol cars. The application will enhance the current capablities of the law enforcement officers. Security is paramount to us. I will keep up with the future releases and hope to see the WSHttpBinding support.

     

    Thank you very much,

    Yosh

  • Where can we download the sample?

  • Yosh,

     

    I wonder which particular security features from WSHttpBinding you are interested in?

  • A sample chat application similar to the one shown in the video can be downloaded from http://tomasz.janczuk.org/2009/07/pubsub-sample-using-http-polling-duplex.html. More resources related to polling duplex are at my blog at http://tomasz.janczuk.org. 

  • John, I'm very happy to see you poking into this area of SL. And much thanks to Tomasz for his solid knowlege. I think [at least personally] the communication power of SL has not been explored fully and I hope to see more series of this type of materials.

    ..Ben

  • Tomasz, although the sample on your blog was built with/for SL3, but I heard you pointed out many things that are new features in SL4, so it might be best to have a SL4 version of the sample.

     

    Thanks!

    ..Ben

  • Hi Tomasz,

     

    Does the WCF duplex communication with Silverlight work in a web farm and on Azure?

     

    Regards,

     

    James.

     

  • Hi Tomasz,

     

    I've found a previous blog of yours, which described a potential solution in SL3 and presumably .NET 3.5 WCF.

     

    http://tomasz.janczuk.org/2009/09/scale-out-of-silverlight-http-polling.html

     

    I'm wondering whether it now works out-of-the-box with SL4 and .NET 4, or does it still require the solution in your post I've linked to.

     

    Regards,

     

    James.

     

  • @Ben - Look at the samples posted here http://blogs.msdn.com/b/silverlightws/archive/2010/03/17/two-samples-from-today-s-mix-2010-talk.aspx . The Video chat example is based on SL4.

  • James,

     

    scale out of the WCF service exposed with the http polling duplex binding in a web farm (Azure or otherwise) is challenging due to the internal design of the server side implementation. Check out http://tomasz.janczuk.org/2009/09/scale-out-of-silverlight-http-polling.html for more details on the topic.

     

    Thanks,

    Tomasz 

  • Nice one, Thanks,

  • Hi Tomasz,

     

    I am very new to programming and I am going through this demo, building it from scratch from your video using Visual Web Developer 2020 Express. I am running Silverlight 4 on Windows XP.  I get to the end of building the server WCF service, press <F5> to run the project. All is well until I try to access the Meta Data by typing the ChatService.svc URL on my localhost. Then I get the error message

     

    "Configuration binding extension 'system.serviceModel/bindings/pollingDuplex' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly."

     

    I gathered from other posts on your blogsite that this is a common problem. I have de-installed and re-installed silverlight to no avail. Any thoughts? What am I doing wrong?

  • sorry that should read Visual Web Developer 2010....

  • eventually got it working by qualifying the BindingExtension with a version,culture and publickeytoken. Also had to put a receiveTimeout on the binding....

     

    <

     

    and

     

     

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

    <pollingDuplex>
            <binding name="myPollingDuplex" duplexMode="MultipleMessagesPerPoll" receiveTimeout="00:30:00"/>
    </pollingDuplex>

  • VirtualVirtual

    Thanks for great videoEveryone  can get the code of this video from the blow address:http://rapidshare.com/files/420956473/SampleChat.rar-------------------------I have a problem within  this tutorial.I get this exception when I try to send a message after 10 seconds ...I changed the receiveTimeout and an others but don't solve.If anyone  had any idea, please comment here.

  • VirtualVirtual

    Excuse me I forget to exception, here is that:The communication object, System.ServiceModel.Channels.ClientPollingDuplexSessionChannel, cannot be used for communication because it is in the Faulted state.
    please help...

  • SasPictoria Avatar Rocks

    Beautiful !

  • LinhLinh

    I get "The communication object, System.ServiceModel.Channels.ClientPollingDuplexSessionChannel, cannot be used for communication because it is in the Faulted state." error when run at finish step of video !
    Sorry i'm new bie for silverlight !

  • BirolBirol

    Hello Tomasz,
    And thank you for the video about duplex protocol. I want to ask that is it possible to use asp.net session and request objects in WCF side for duplex protocol.For example I want to get the user agent of the client browser. When I try this,I get null object. We used webHttpBinding protocol in another project and we could use request object. if we use duplex protocol,we dont get it.
    Thanks.

  • Very good, sorry the source to this is not available.  I have an application where the customer brings up inventory, say there are 50 widgets in stock.  Now, somebody removes 5 from stock, leaving 45, and updating their screen.  Would this application work well to notify my station of the inventory change, correcting my screen to the 45 without me touching it?

  • Great demo.  Thanks Tomasz!

  • VijayVijay

    I am getting the following exception:
     
    "The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."
     
    While debugging I got to know that the client channel is entering Fault state because of which further calls to service is failing.
     
    Any quick help on this will be appreciable.
     

  • MohammadMohammad

    I have written a WCFService and WCFClient working on Duplex Channel on netTCPBinding. It is working fine for some time, after that WCFClient stops the channelling intermmitently and one of the errors as shown below:

    "The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state."
     

  • I followed your excellent video and build a sample using http://msdn.microsoft.com/en-us/library/cc645027(v=vs.95).aspx">http://msdn.microsoft.com/en-us/library/cc645027(v=vs.95).aspx and thanks to both sources
    thing looked great till we turned on Windows authentication"  and turned off "allow anonymous authentication" on the service using IIS console. We
    have alot of security minded clients and the thought of enabling
    this makes them run for the hills! I know that this should not present a security issue as the service will use Windows auth
    but the client is always right. When we do this we get the following error:

    Exception: System.ServiceModel.ServiceActivationException: The service '/DuplexService1/Service1.svc' cannot be activated
    due to an exception during compilation.  The exception message is: Security settings for this service require 'Anonymous'
     Authentication but it is not enabled for the IIS application that hosts this service.. ---> System.NotSupportedException: Security
    settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

    Now we also tried building a CustomBinding

    <system.serviceModel>
        <!-- Register the binding extension from the SDK. -->
        <extensions>
          <bindingElementExtensions>
            <add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexElement, System.ServiceModel.PollingDuplex"/>
          </bindingElementExtensions>
          <bindingExtensions>
                    <add name="pollingDuplexHttpBinding" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          </bindingExtensions>
        </extensions>
        <!-- Create the polling duplex binding. -->
        <bindings>
           <customBinding>
            <binding name="pollingBindingConfig" closeTimeout="00:01:05" openTimeout="00:01:05" receiveTimeout="00:01:10" sendTimeout="00:01:10">
              <binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                maxSessionSize="2048">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              </binaryMessageEncoding>
              <pollingDuplex maxPendingSessions="2147483647"
                             maxPendingMessagesPerSession="2147483647" />


              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Negotiate"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Negotiate"
                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                useDefaultWebProxy="true" />
            </binding>
          </customBinding>


        </bindings>

        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- 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>
        <services>
          <service name="DuplexService1.OrderService">

            <!-- Service Endpoints -->
            <endpoint address="" binding="customBinding"  bindingConfiguration="pollingBindingConfig" contract="DuplexService1.IDuplexService">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>

    again the same result. The other curious thing is the that the SL ClientConfig file is always empty.(<configuration />. Surely SL Duplex communications does not
    require Anonymous auth to be on or we are up the creek.

  • thanks  to this great post  http://ajdotnet.wordpress.com/2010/08/08/silverlight-and-integrated-authentication/#comment-8636  I kind of solved the problem by  removing MEX endpoint  But this seems like a bug me as MEX should only be used in discovery. The really wierd part is that after I remove the MEX endpoint and disable anonymous auth for the service I can still update my service from the SL client. Go fiqure something is not good here

  • for a wonderful and simple (I like simple ) see Jeff Prosise's article http://www.wintellect.com/CS/blogs/jprosise/archive/2009/08/27/silverlight-3-s-new-and-improved-duplex-networking-clients.aspx

    This really helped me as we needed more like Jeff is doing as we wanted our SL UI to repond to server progress events and the duplexMode="MultipleMessagesPerPoll" was causing my responses to be buffered so it looked like they were not working. Looking at Jeffs example cleared the air. It worked fine after converting project to SL4

  • Aleksei jusevAleksei jusev

    Hi,
    I am tring to follow your video tutorial and I am stuck with this error when I am trying to check the service on the browser...
    Configuration binding extension 'system.serviceModel/bindings/pollingDuplex' could not be found.
    In my  binding Extensions i DO have this:

  • CarmenCarmen

    Is there any way to get the source code ??? ... because he keeps on making references to his blog

  • AzerusAzerus

    Is it working in the OOB mode ?

  • OMAR OLGUINOMAR OLGUIN

    El ejemplo no funciona,
    incluso bajandolo para ejecutarlo tampoco,

    tengo visual studio 2010
    silverlight 3.0
    y windows 7

    manda un mensaje de error: Error NotFound

  • Fernando vergaraFernando vergara

    Hi!

    Excellent example, but I have a question.

    how to control the crowd of clients addend to list?

    because, if a client disconnects. return a error when trying to send the message.


    public sub publish (byval message as string )
    dim callback as IduplexService

    for each callback in Clients
    try
    callback.Notify(message)
    catch ex as Exception
    '<return a error. if a client disconnects>
    end try
    next

    end sub

  • Hi Tomasz,

    I'm trying to write a subscription service similar to this chat service.  Below is my web.config:

    <?xml version="1.0"?>
    <configuration>

    <system.web>
    <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
    <extensions>
    <bindingElementExtensions>
    <add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingElement, System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </bindingElementExtensions>
    </extensions>
    <bindings>
    <customBinding>
    <binding name="MAD.ChangeNotificationServices.SubscriptionService.customBinding0">
    <binaryMessageEncoding />
    <pollingDuplex duplexMode="MultipleMessagesPerPoll"></pollingDuplex>
    <httpTransport />
    </binding>
    </customBinding>
    </bindings>
    <services>
    <service name="MAD.ChangeNotificationServices.SubscriptionService">
    <endpoint address="" binding="customBinding" bindingConfiguration="MAD.ChangeNotificationServices.SubscriptionService.customBinding0"
    contract="MAD.ChangeNotificationServices.ISubscriptionService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
    </services>
    <behaviors>
    <serviceBehaviors>
    <behavior>
    <!-- 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"/>
    <serviceThrottling maxConcurrentSessions="2147483647"/>
    </behavior>
    </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
    multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

    </configuration>

    When I use SingleMessagePerPoll as my duplex mode, everything works fine.  But when I switch to MultipleMessagesPerPoll, calls to the subscription service result in an operation timeout after 1 minute.  If I place a break point in the method I am calling in the subscription service, the break point is never hit.  Do you have any wisdom to share?

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.