Saturday, November 10, 2007
« WCF Webcast Series | Main | Learning WCF Code: VS 2008 »

If you are using VS 2008 (Beta 2) there are changes to the tools that affect this lab in Chapter 1. Here are a summary of changes for each step that is affected in the lab starting on Page 32 of Learning WCF.

Section 1: Using the WCF Service template

  • Step 3: Open IHelloIndigoService.cs instead of HelloIndigoService.cs.
  • Step 4: Open HelloIndigoService.cs to modify the class.
  • Step 5 + 6: VS 2008 does not create a MyServiceHost helper class so you will have to host the service yourself as you did in the previous lab by adding the following code to the Program.cs file:
using System.ServiceModel;

static void Main(string[] args)

{
  using (ServiceHost host = new ServiceHost(typeof(Host.HelloIndigoService)))
  {
     host.Open();
     Console.WriteLine("Press <Enter> to terminate the service host.");
     Console.ReadLine();
   }
}
  • Step 7: Before you compile and run the Host project, delete the <system.serviceModel> section from the App.Config so that you can create a new configuration section from scratch in the next section, instead of using what was generated for you already. In VS 2008, the WCF Service template already created an endpoint configuration for the service in the App.config. The new configuration should look like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

Section 2: Configuring service endpoints using the Service Configuration Editor

  • Step 1: In VS 2008 (Beta 2) to open the WCF Service Configuration Editor you have to go to the Tools -> WCF SvcConfigEditor menu item. Then you have to open the App.config file by browsing to it in the file open dialog. Select File->Open->Config File and browse from there. Hopefully they will bring back the context menu in the final release of VS 2008.
  • Step 8: In VS 2008 (Beta 2) when you run the Host project in Debug mode you can't add a service reference to the client. So, run the Host project without debugging in this step to avoid this problem. Hopefully this will be fixed before release.

Section 3: Generating a proxy with Add Service Reference

  • Step 1: Name the service reference "localhost" to match the other steps in this lab. VS 2008 names services references "ServiceReference" instead. Click Go to find the metadata for the service, then click OK to add the service reference. In VS 2008 the hierarchy of the generated metadata files is slightly different, and location of the service metadata is in Reference.cs not localhost.cs.

Section 4: Creating a WCF Service Library

  • Step 1: In VS 2008 (Beta 2) you'll find the WCF Service Library template under the WCF category of templates. Do not choose WCF Service Application from the main set of templates.
  • Step 2: Rename IService1.cs to IHelloIndigoService.cs, and Service1.cs to HelloIndigoService.cs.
  • Step 3: Open IHelloIndigoService.cs to modify the contract.
  • Step 4: Open HelloIndigoService.cs to modify the class. Delete all the extra code created for you.
  • Step 7: Open Program.cs to modify the ServiceHost type.
Technorati Tags: ,
Tuesday, November 27, 2007 12:47:57 AM (GMT Standard Time, UTC+00:00)
In section 4 (Creating a WCF Service Library) using VS08 RTM, I think that you will also have to delete the App.Config file that VS generates for the library. Although a DLL isn't supposed to have an App.Config file, somehow having it around causes problems, even when its contents are identical to the host console app's App.Config file.

Before I realized that you had to delete the library's App.Config, my lab got VERY confused and stopped working. So I started from scratch. I went back to the downloaded, virgin VS08 project with just the Host and Client apps. Then (having learnt from experience) I changed the target .NET Framework version to .NET 3.5 in both cases. Then I generated and made the requisite changes to the WCF Service Library (section 4). Then I made the requisite changes to the Host app. Then I modded the library's App.Config file. Then I copied the libary's App.Config file to the host's App.Config file (overwriting any previous contents in the latter), and deleted the library original. Then I ran the host app (in non-debug) and added the service reference to the client app (reading the service data from the running host app). Then I closed the host, made the requisite changes to the client, and run both client and server. Now I've got a working app, but it's slow. So I used the Service Configuration Editor to change the host to use BasicHttp binding instead of WsHttp binding. Deleted the service reference in the client, and re-generated from the re-run host. Ran both client and host again, and this time the speed wass as before (fast) and I've got a fully working app. Phew!

Getting the lab all messed up and sorting it out from scratch was a great way to learn.

Andrew Webb
Saturday, December 01, 2007 12:37:45 AM (GMT Standard Time, UTC+00:00)
I'm using Visual Studio 2008 (RTM).

On page 53 it says: "Run the web site from within Visual Studio (F5)." But when I did this I got an HTTP 403 error each time. It took me a long time to work out that you have to have the .svc file selected in the Solution Explorer before you launch the web site. This is because the default startup action is to open the current page. As a developer who's come from WinForms, I didn't see that one coming at all!

Pages 53-54: the template that ships with VS08 enables metadata exchange with HTTP GET by default, so you don't have to perform these steps.

Andrew Webb
Tuesday, January 08, 2008 1:22:37 AM (GMT Standard Time, UTC+00:00)
With regard to your comment on Section 2, Step 1:
>> Hopefully they will bring back the context menu in the final release of VS 2008.

Indeed they have. In Visual Studio 2008 RTM, the context menu "Edit WCF Configuration" has been re-introduced.

If you are using RTM or later, you can now right-click the app.config file and select this option instead of launching the WCF Service Configuration Editor.
Matt Slater
Comments are closed.
    About the Book
    ON THIS PAGE
    CATEGORIES
    ARCHIVES
    DASBLONDE

Designed by NUKEATION STUDIOS