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.
Great stuff Ron!!. I think it would be a great idea to simplify the configuration story for this scenario by adding some code in the template for configuring all this stuff for you if the project has a web.config file (so removing the manual steps for configuring monitoring and routing). Adding the service route in the global.asax is perhap more complicated but it can be also be done in the template. Just some feedback :).
Hi, it's a really useful template !!
We are thinking of using this as an application layer implementation, but are there any way, that we can use the tcp/ip protocol instead of http protocol?. We will implement an entity Server that communicates to the client through WCF services, and we were hoping to use the AppFabric WCF Data services, but we are concerned about the performance when using the http protocol.
Dennis - I have a WCF SOAP version of the template that will be ready tomorrow. That should help you and you can use tcp/ip with it.
Hi Ron,
Thanks for your quick reply. I did a typing error in my earlier question, instead of "tcp/ip" I ment "net.tcp", do you know if thats going to be possible in the future? Are there any plans concerning that protocol?
Sorry for the typing error !
net.tcp == tcp/ip so no worries.
The WCF Service Template is now available at visualstudiogallery.msdn.microsoft.com/633afbb4-1c97-4128-b22e-65954d450b64
This is pretty cool. I really like the guidance part, makes it so much easy to try it out. I agree with Pablo on simplifying configuration.
Still new to the Appfabric/WCF Stack. Can you tell me when it's recommended to use the "AppFabric WCF HTTP Service" Template over the "AppFabric WCF Service " Template. Does it have anything to do with the endpoint binding
Good Stuff