Skip to main content

WCF Custom Help Page

A sample showing how to implement a custom help page for WCF endpoints, similar to the one enabled in .NET 4.0 for REST endpoints.

C# (42.3 KB)
4 Star
2,371 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • IIS Hosted service
    3 Posts | Last post October 12, 2016
    • Hi Carlos
      Great post....
      But how would you do it with a IIS hosted service?? I've tried the following, but I can't seem to get it work:
          public class Global : HttpApplication
              void Application_Start(object sender, EventArgs e)
              private void RegisterRoutes()
                  // Edit the base address of Service1 by replacing the "Service1" string below
                  var factory = new MyServiceHostFactory();
                  RouteTable.Routes.Add(new ServiceRoute("Service1", factory, typeof(Service1)));
          public class MyServiceHostFactory : WebServiceHostFactory
              public MyServiceHostFactory ()
              protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
                  return new MyServiceHost(serviceType, baseAddresses);
          public class MyServiceHost : WebServiceHost
              public MyServiceHost(Type serviceType, Uri[] baseAddresses): base(serviceType, baseAddresses)   
              public override void AddServiceEndpoint(System.ServiceModel.Description.ServiceEndpoint endpoint)
                  endpoint.Behaviors.Add(new HelpPageEndpointBehavior("ACME LLC"));
      any ideas ?
    • Interesting, I'm getting an error in webhost as well. I've tried to fix that error for a while without success, I'll continue trying over the next few days and if I'm successful I'll post an update here. Thanks for pointing it out!
    • In case anyone else comes across this problem, the easiest way around the problem of staging a custom help page for a dynamic service was to create a new endpoint (/MyNormalEndpoint/HelpEndpoint) and then tie into "UnhandledDispatchOperation" with some changes to the ApplyDispatchBehavior.
               public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
                  HelpPageService service = new HelpPageService(endpoint, this.companyName);
                  DispatchOperation operationDispatcher = new DispatchOperation(endpointDispatcher.DispatchRuntime,"GetHelpPage", "*", "*");
                  operationDispatcher.Formatter = new PassthroughMessageFormatter();
                  operationDispatcher.Invoker = new HelpPageInvoker(service);
                  operationDispatcher.SerializeReply = false;
                  operationDispatcher.DeserializeRequest = false;
                  endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation = operationDispatcher;
                  endpointDispatcher.DispatchRuntime.InstanceProvider = new SingletonInstanceProvider(service);
                  endpointDispatcher.DispatchRuntime.InstanceContextProvider = new SimpleInstanceContextProvider();
                  endpointDispatcher.DispatchRuntime.SingletonInstanceContext = new InstanceContext(endpointDispatcher.ChannelDispatcher.Host, service);
                  endpointDispatcher.ContractFilter = new MatchAllMessageFilter();
                  endpointDispatcher.FilterPriority = 0;
  • How to Modify the Service Method Help
    2 Posts | Last post June 07, 2012
    • Hi Carlos
      your post help me alot,
      Can you please explain how to modify the service method help page.
    • Saboor, you can't really *modify* the service help page created by WCF; you can only *replace* it instead, as was shown in this sample. One alternative, if possible, is to move to the ASP.NET Web API, where the help page system is extensible - see more information at