Since I posted the code for a basic service/client, I’ve gotten a few requests for additional functionality, particularly the code that we used to demo the security/logging functionality Payam showed.  Here’s what you do:

 

-first of all, let’s simplify the App.config file in the Magic8BallClient.  Until now, we’ve been using code generated by svcutil.  svcutil tries to set all sorts of configuration settings based on the metadata it gets.  But we happen to know exactly what binding the service uses (basicProfileBinding) and so we can just set the client config to the following:

 

<?xml version="1.0" encoding="utf-8"?>

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

    <system.serviceModel>

        <client>

            <endpoint

                        address="http://localhost/magic8ballservice"

                        bindingSectionName="basicProfileBinding"

                contractType="Magic8BallService">

            </endpoint>

        </client>

    </system.serviceModel>

</configuration>

 

You can check that this works by running the service/client again.

-now let’s add the logging.  Replace the App.config file in the Magic8BallService solution with the following code:

<configuration>

      <system.serviceModel>

            <services>

                  <service serviceType="Magic8Ball.Magic8BallService">

                        <endpoint

                              address="http://localhost/magic8ballservice"

                              bindingSectionName="basicProfileBinding"

                              contractType="Magic8Ball.Magic8BallService" />

                  </service>

            </services>

            <diagnostics performanceCountersEnabled="true">

                  <messageLogging logEntireMessage="true" maxMessagesToLog="300" maxNumberOfFilters="1"

                                                              logMessagesAtServiceLevel="false"

                                                              logMalformedMessages="true"

                                                              logMessagesAtTransportLevel="true">

                        <transportFilters>

                              <add xmlns:soap="http://www.w3.org/2003/05/soap-envelope">/soap:Envelope</add>

                        </transportFilters>

                  </messageLogging>

                  </diagnostics>

            </system.serviceModel>

      <system.diagnostics>

            <sources>

                  <source name="IndigoMessageLogTraceSource" switchValue="Verbose">

                        <listeners>

                              <add name="multifile" type="System.ServiceModel.Diagnostics.MessageWriterTraceListener, System.ServiceModel, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

                                       initializeData=".\talog\" maxDiskSpace="1000" />

                        </listeners>

                  </source>

            </sources>

      </system.diagnostics>

</configuration>

 

This adds diagnostic functionality to the service.

-run the service and client again.  Take a look at the files in Magic8BallService/Magic8BallService/bin/debug/talog, and you’ll see two files which carry the cleartext request from the client and response from the service.

-now we’ve got to change the config files on both sides to use security. First, let’s change the binding in the config on the service side from

bindingSectionName="basicProfileBinding"

to

bindingSectionName="wsProfileBinding"

Now the service will use security. 

-we need to change the binding on the client side in the same way.  Try running the client and service before you change the binding on the client side, and you’ll find that you get a “binding mismatch” error.

-shut down the client, and change the client binding to use security.  Take a look at the log files.  This time there were eight generated.  The first six were part of the handshake setting up the secure connection between the client and the service.  The 7th and 8th files actually contain the request and response (you can see the Actions in the message headers) as encrypted CipherValues.

And that’s it—you’ve just added security to an existing service/client.

 

okay, time for me to upgrade to the CTP release.