This sample demonstrates how to activate Windows Communication Foundation (WCF) services without requiring a .svc file.
The samples may already be installed on your computer. Check for the following (default) directory before continuing.
In this sample, the client is the WCF test client and the service is hosted in IIS.
|The setup and build instructions for this sample are located at the end of this topic.|
Activation of services without requiring a .svc file
In .NET Framework 3.5, a .svc file was required for activating a service. This caused additional management overhead, because an additional file was required to be deployed and maintained along with the application. With the release of .NET Framework version 4, the activation components can be configured using the application configuration file.
.NET Framework 4 introduces a new configuration element (ServiceActivationElement), in the ServiceHostingEnvironmentSection of the application configuration file. The ServiceHostingEnvironmentSection collection accepts a collection of services to activate, as shown in the following code example.
<serviceActivations> <add relativeAddress="Calculator.svc" service="Microsoft.ServiceModel.Samples.CalculatorService" /> <serviceActivations>
The observation to make is the configuration looks very similar to the configuration of .svc files. An additional attribute that is introduced is the
relativeAddress that provides the address of the service. The relative address is also the virtual path for the service. The host retrieves the Web.config file of the file from the
virtualPath location, if present; otherwise the host searches its parent folder recursively.
|This sample requires hosting in IIS to function.|
To use this sample
Using Visual Studio 2012, open the Service.csproj file.
To build the solution, press CTRL+SHIFT+B.
Test the service by running WCFTestClient.exe.
Using File Explorer, navigate to the %SystemDrive%\Program Files\Microsoft Visual Studio 10.0\Common7\IDE folder.
Set the MEX address of the service.
Press CTRL+SHIFT+A to set the service address.
Set the address to http://localhost/ServiceModelSamples/Calculator.svc.
Addoperation. Set value on the
n1parameter to 10 and set value on the
n2parameter to 15.
The expected result is 25.
To set up, build, and run the sample
Be sure you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.
To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.
After the solution has been built, run Setup.bat to set up the ServiceModelSamples Application in IIS. The ServiceModelSamples directory should now appear as an IIS Application.
To run the sample in a single- or cross-computer configuration, follow the instructions in Running the Windows Communication Foundation Samples.
Other ResourcesAppFabric Hosting and Persistence Samples