Windows Communication Foundation (WCF) is Microsoft’s unified programming model for building service-oriented applications. Windows Server AppFabric provides tools for managing and monitoring your web services and workflows. WCF HTTP Service is a service that can be accessed by a simple HTTP POST/GET request and can return responses in plain XML and in JSON formats.
The AppFabric WCF HTTP Service template brings these two products together providing the following features:
To build and test an AppFabric WCF HTTP Service you will need the following:
1: public string SayHello(string name)
2: {
3: // Output a warning if name is empty
4: if (string.IsNullOrWhiteSpace(name))
5: AppFabricEventProvider.WriteWarningEvent(
6: "SayHello",
7: "Warning - name is empty");
8: else
9: AppFabricEventProvider.WriteInformationEvent(
10: "SayHello",
11: "Saying Hello to user {0}",
12: name);
13:
14: return "Hello " + name;
15: }
1: <microsoft.applicationServer>
2: <monitoring>
3: <default enabled="true" connectionStringName="ApplicationServerMonitoringConnectionString" monitoringLevel="EndToEndMonitoring" />
4: </monitoring>
5: </microsoft.applicationServer>
6:
7: <system.serviceModel>
8: <diagnostics etwProviderId="830b12d1-bb5b-4887-aa3f-ab508fd4c8ba">
9: <endToEndTracing propagateActivity="true" messageFlowTracing="true" />
10: </diagnostics>
11: <behaviors>
12: <serviceBehaviors>
13: <behavior>
14: <etwTracking profileName="EndToEndMonitoring Tracking Profile" />
15: <serviceMetadata httpGetEnabled="true" />
16: </behavior>
17: </serviceBehaviors>
18: </behaviors>
19: </system.serviceModel>
1: <system.serviceModel>
2: <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
3: </system.serviceModel>
1: <system.webServer>
2: <modules runAllManagedModulesForAllRequests="true">
3: <remove name="UrlRoutingModule"/>
4: <add name="UrlRoutingModule"
5: type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
6: </modules>
7: <handlers>
8: <add name="UrlRoutingHandler"
9: preCondition="integratedMode"
10: verb="*"
11: path="UrlRouting.axd"
12: type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
13: </handlers>
14: </system.webServer>
You Must Enable HTTP Redirection
The UrlRoutingHandler will not work if the HTTP Redirection feature of IIS is not installed (more info)
1: using System.Web.Routing;
2: using System.ServiceModel.Activation;
1: protected void Application_Start(object sender, EventArgs e)
3: RouteTable.Routes.Add(new ServiceRoute(
4: "SampleService", /* Replace SampleService with your service name */
5: new WebServiceHostFactory(),
6: typeof(SampleService))); /* Replace SampleService with your service name */
7: }
If you are using Internet Explorer 9, you might see the following error message: “The XML page cannot be displayed”
To view the XML response of the service, open the View menu and select Source.
To see the events in Windows Server AppFabric you need to deploy the Web project to IIS or modify your project to host the solution in the local IIS Server. For this example you will modify the project to host with the local IIS server.
Run Visual Studio as Administrator
If you are not running Visual Studio as Administrator, exit and restart Visual Studio as Administrator and reload your project. For more information see Using Visual Studio with IIS 7.