Running and Testing Your WCF Service

Whether you create a WCF Service Application (hosted in a website) or a WCF Service Library (hosted independently of the service definition), Visual Studio provides a mechanism for running and debugging your services without your having to deploy them first or write your own service client.

In the example, we created a WCF Service Application. Visual Studio leverage IIS Express to host this service. Visual Studio provides you a test client to run and debug the service. To use this test client, select your service in Solution Explorer (CustomerProfile.svc) and, from the Debug menu, select Start Debugging (or just press F5). Visual Studio will run the code in debug mode using the WCF Test Client, as shown in Figure 19.21.

Image

FIGURE 19.21 The WCF Test Client can help you test and debug your services.

Notice in Figure 19.21 that the WCF Test Client shows your service and all its operations. The operations marked with the red ‘x’ indicate the async versions of your service (which cannot be accessed by the test client).

You double-click a given service to go to the test client for that service (right-side of Figure 19.21). Notice that there are multiple tabs at the top of this form section. These are all the services currently being tested. You can also see the Get(id) service in action. Notice that the test client gives you a place to define parameters (Request section) and a button to invoke the service. The bottom section shows the response from the service.

Notice, too, that at the bottom of the form in the Response area, you can toggle between the formatted results and XML. The XML view shows both the Request and the Response as markup. This can be useful when debugging. To stop testing, select File, Exit in the WCF Test Client.


Tip: Configure Endpoints

After your service exists, you can edit its configuration to support various clients. This means adding endpoints and related configuration information. Remember, the promise of WCF is that you can create a single service and then optimize it to work with multiple clients. One client might access via HTTP, another through TCP, and yet another with named pipes. You can support all of these clients (and more) through configuration.

The WCF Service Library template contains an App.config file. The WCF Service Application contains the file Web.config. Both files define your service configuration. Typically, you edit the Web.config file using the XML editor in Visual Studio. However, when dealing with Service Library projects and multiple endpoints, it can be easier to edit this information using the Service Configuration Editor tool. To access this tool, right-click the config file and choose Edit WCF Configuration.

If you’re using Web.config, you want to click the Create a New Service link in this configuration editor. A wizard then walks you through the process to connect to configuration information about your service. From there, you can add endpoints and bindings as appropriate.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset