Steve Holstad's "the bright lights"

"Just because your voice reaches halfway around the world doesn't mean you are wiser than when it reached only to the end of the bar." - Edward R. Murrow
in

Coding4Fun: YeahTrivia client & server using WCF & WPF

I spent the last couple of weeks creating a posting for Coding4Fun's blog site, called YeahTrivia. The demo consists of a WCF client & server communicating via the wsDualHttpBinding channel. I used the article to learn quite a bit about implementing WCF to abstract service communication outside of an app's core code.  Learning this new design pattern is a bit intimidating:  I find that the hardest part in shifting your thought process is to take the first step... awhile back I attended Juval Lowy's WCF class, but until now haven't had time to apply it.

I'll be posting some of my favorite features of WCF and WPF as I continue to dive in. Be sure to check out the demo and tell me what you think.

To start, here are the config files of the client and server I used to create a wsDualHttpBinding communication channel:

Server:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<appSettings>
    
<add key="BaseURI" value="http://localhost:8088/Trivia"/>
    <
add key="QuestionLoadDelay" value="4000"/>
    <
add key="QuestionTime" value="11000"/>
  </
appSettings>

  
<system.serviceModel>
    
<services>
      
<service name="Trivia.Server.GameServer" behaviorConfiguration="MyServiceTypeBehaviors">
        
<endpoint address="http://localhost:8088/Trivia"
                  binding
="wsDualHttpBinding"
                  contract
="Trivia.Common.ITrivia" />
            <
endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
        </
service>
    
</services>
      
<behaviors>
          
<serviceBehaviors>
              
<behavior name="MyServiceTypeBehaviors" >
                  
<serviceMetadata httpGetEnabled="true" />
              </
behavior>
          
</serviceBehaviors>
      
</behaviors>
  
</system.serviceModel>
</configuration>

Client:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    
<system.serviceModel>
        
<bindings>
            
<wsDualHttpBinding>
                
<binding name="WSDualHttpBinding_ITrivia"
                         clientBaseAddress
="http://localhost:8082/Trivia/" 
                         closeTimeout
="00:01:00"
                         openTimeout
="00:01:00" 
                         receiveTimeout
="00:10:00" 
                         sendTimeout
="00:01:00"
                         bypassProxyOnLocal
="false" 
                         transactionFlow
="false" 
                         hostNameComparisonMode
="StrongWildcard"
                         maxBufferPoolSize
="524288" 
                         maxReceivedMessageSize
="65536"
                         messageEncoding
="Text" 
                         textEncoding
="utf-8" 
                         useDefaultWebProxy
="true">
                    
<readerQuotas maxDepth="32" 
                                  maxStringContentLength
="8192" maxArrayLength="16384"
                        maxBytesPerRead
="4096" maxNameTableCharCount="16384" />
                    <
reliableSession ordered="true" inactivityTimeout="00:10:00" />
                    <
security mode="Message">
                        
<message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite
="Default" />
                    </
security>
                
</binding>
            
</wsDualHttpBinding>            
        
</bindings>
        
<client>
            
<endpoint address="http://localhost:8088/Trivia" binding="wsDualHttpBinding"
                bindingConfiguration
="WSDualHttpBinding_ITrivia" contract="Trivia.Common.ITrivia"
                name
="WSDualHttpBinding_ITrivia">
            
</endpoint>
        
</client>
    
</system.serviceModel>
</configuration>

The client config contains some extra binding attributes that are optional, but I wanted to show you the exact files that were generated using the Svcutil utility.  Use Svcutil.exe to generate a proxy class which, when created and added to your client project, is used to marshal calls via WCF to the service.  To generate my client class, I started my service and ran the following at the command line:

svcutil /language:cs /out:ServerProxy.cs http://localhost:8088/Trivia

Not a complete solution, but should get you started in the right direction. For a working example, check out the article and let me know if you have any questions.

 

Technorati Tags: , ,
Del.icio.us Tags: , ,

Comments

Coding4Fun said:

In this article I'll take you along for the ride as I attack the learning curve required to create a
# October 29, 2007 6:58 PM