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"?>
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:
<messageLogging logEntireMessage="true" maxMessagesToLog="300" maxNumberOfFilters="1"
<source name="IndigoMessageLogTraceSource" switchValue="Verbose">
<add name="multifile" type="System.ServiceModel.Diagnostics.MessageWriterTraceListener, System.ServiceModel, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089"
initializeData=".\talog\" maxDiskSpace="1000" />
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
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.