4

So I've created a WCF service application and hosted it on IIS7. It currently has a few test 'helloworld' methods. When I run it in my browser I get this screen: enter image description here

Now the service itself works great, but how can I display the operations like this: enter image description here

Thanks to marc_s for the link: http://www.dotnetcurry.com/ShowArticle.aspx?ID=399 which I've followed so my web config is now setup like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfServer.Service1">
        <endpoint address="" binding="webHttpBinding" contract="WcfServer.IService1" behaviorConfiguration="HelpBehaviour" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <enableWebScript />
        </behavior>
        <behavior name="HelpBehaviour">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension" />
  </system.webServer>
</configuration>

However, this only works locally. When I publish to my server on IIS7 I get a 404 error page when I click on the help link. Does anyone know why this is, or has come across it before?

(Last bit was solved by running: aspnet_regiis.exe -iru)

ingh.am
  • 25,981
  • 43
  • 130
  • 177
  • You are best using the WCFTestClient to test WCF in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE (for VS 2010) – PMC Feb 03 '11 at 12:14
  • This was the first thing I did: which works fine! – ingh.am Feb 03 '11 at 12:24

1 Answers1

9

If you have a WCF service with a SOAP binding, you're unfortunately out of luck: there's no way in WCF out of the box to get a listing similar to ASMX with all the services.

With REST binding (webHttpBinding) and .NET 4.0, you can have an automatic help page generated which lists the URI templates, the HTTP methods supported and so forth. You can also tweak that page to a certain degree.

In order to have that automatic help page generated, you need to define (and reference) an endpoint behavior:

<behaviors>
   <endpointBehaviors>
       <behavior name="HelpBehavior">
           <webHttp helpEnabled="true" />
       </behavior>
   </endpointBehaviors>
</behaviors>

Then reference that behavior from your webHttpBinding endpoint, and you're done.

Read all about it:

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 2
    +1 I was just writing the same answer. I would only add that help page URL for REST service has sufix /help : http://msdn.microsoft.com/en-us/library/ee230442.aspx – Ladislav Mrnka Feb 03 '11 at 12:22
  • How can I get the automatic help page generated? I'm using .NET 4.0 and was attempting to do REST services but the web.config doesn't have any endpoints defined. Do I have to write these myself? – ingh.am Feb 03 '11 at 12:26
  • Where it talks about "default endpoints", do they get used when none are defined then? – ingh.am Feb 03 '11 at 12:30
  • 1
    @ing0: yes, if you define no endpoints at all, WCF 4 will kick in some default endpoints, based on your base address(es) defined, and your service contract. As soon as you define even a single endpoint, then only that endpoint of your is used – marc_s Feb 03 '11 at 12:31
  • 1
    Right ok thanks, I need to write an endpoint which I then reference my help behaviour too. – ingh.am Feb 03 '11 at 12:32
  • 1
    Thanks for providing the info I needed marc! – ingh.am Feb 03 '11 at 15:07