none
Is there a way to list all WCF OperationContract on a web page like what asmx can do? RRS feed

  • Question

  • With asmx sevice, you can have a web page that shows all the service method when a client navigate to the asmx via web browser.  Is there a way to do the same with WCF?  I understand that by append ?wsdl you will see the wsdl.  But it would be nice that I can a clean page like asmx that list all the OperationContract in a non wsdl format.
    Friday, January 18, 2013 3:07 PM

Answers

  • Hi,

    >> Can I set this behavior using web config?  Can this be used for WCF soap service?

    As Shyam said, it is added in the <endpointBehaviors> tag and apply the behaviorConfiguration for the service. This is used for WCF WEB HTTP services not soap services.

    >>What address doi need to type in browser url to be able to see the operations listed as in asmx?

    When a user browses to a WCF WEB HTTP service and appends "/Help" on to the end of the URL, for example http://localhost:8000/Customers/Help. Please take a look at this document for details.

    #WCF Web HTTP Service Help Page

    http://msdn.microsoft.com/en-us/library/ee230442(v=vs.110).aspx

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by mysti789 Friday, January 25, 2013 5:40 PM
    Thursday, January 24, 2013 1:31 AM
    Moderator

All replies

  • Hi,

    For .NET Framework 4.0 or later versions, it provides an automatic help page for WCF WEB HTTP services, it lists a description of each operation, request and response formats, and schemas. You can enable this functionality by adding a WebHttpBehavior to the endpoint setting EnableHelp to true.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 21, 2013 6:07 AM
    Moderator
  • Thank you for your reply.  Can I set this behavior using web config?  Can this be used for WCF soap service?
    • Edited by mysti789 Wednesday, January 23, 2013 2:12 PM
    Wednesday, January 23, 2013 2:12 PM
  • Yes you can set this in Web.config.

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

    Hope this helps.

    One good question is equivalent to ten best answers.

    Wednesday, January 23, 2013 4:03 PM
  • I am learning to use WCF and would like to see the wcf operations in the browser as accessible in asmx file. 

    My Question :

    1)Where do I add the code  

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

    2) What address doi need to type in browser url to be able to see the operations listed as in asmx?

    Here is the Service :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    using System.Data;
    using System.Data.Sql;
    using System.Data.SqlClient;


    namespace Microsoft.ServiceModel.Samples
    {
        // Step 6: Define a service contract.
        [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
        public interface ICalculator
        {
            // Step7: Create the method declaration for the contract.
            [OperationContract]
            double Add(double n1, double n2);
            [OperationContract]
            double Subtract(double n1, double n2);
            [OperationContract]
            double Multiply(double n1, double n2);
            [OperationContract]
            double Divide(double n1, double n2);
          
        }
        // Step 1: Create service class that implements the service contract.
        public class CalculatorService : ICalculator
        {
            // Step 2: Implement functionality for the service operations.
            public double Add(double n1, double n2)
            {
                double result = n1 + n2;
                Console.WriteLine("Received Add({0},{1})", n1, n2);
                // Code added to write output to the console window.
                Console.WriteLine("Return: {0}", result);
                return result;
            }

            public double Subtract(double n1, double n2)
            {
                double result = n1 - n2;
                Console.WriteLine("Received Subtract({0},{1})", n1, n2);
                Console.WriteLine("Return: {0}", result);
                return result;
            }

            public double Multiply(double n1, double n2)
            {
                double result = n1 * n2;
                Console.WriteLine("Received Multiply({0},{1})", n1, n2);
                Console.WriteLine("Return: {0}", result);
                return result;
            }

            public double Divide(double n1, double n2)
            {
                double result = n1 / n2;
                Console.WriteLine("Received Divide({0},{1})", n1, n2);
                Console.WriteLine("Return: {0}", result);
                return result;
            }

           
           
        }


        class Program
        {
            static void Main(string[] args)
            {

                // Step 1 of the address configuration procedure: Create a URI to serve as the base address.
                Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service");

                // Step 2 of the hosting procedure: Create ServiceHost
                ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);

                try
                {


                    // Step 3 of the hosting procedure: Add a service endpoint.
                    selfHost.AddServiceEndpoint(
                        typeof(ICalculator),
                        new WSHttpBinding(),
                        "CalculatorService");


                    // Step 4 of the hosting procedure: Enable metadata exchange.
                    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                    smb.HttpGetEnabled = true;
                    selfHost.Description.Behaviors.Add(smb);

                    // Step 5 of the hosting procedure: Start (and then stop) the service.
                    selfHost.Open();
                    Console.WriteLine("The service is ready.");
                    Console.WriteLine("Press <ENTER> to terminate service.");
                    Console.WriteLine();
                    Console.ReadLine();

                    // Close the ServiceHostBase to shutdown the service.
                    selfHost.Close();
                }
                catch (CommunicationException ce)
                {
                    Console.WriteLine("An exception occurred: {0}", ce.Message);
                    selfHost.Abort();
                }

     

            }
        }
    }

    Here is the application.config for Service

    <?xml version="1.0"?>
    <configuration>
    <configSections>
    </configSections>

      <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

    Wednesday, January 23, 2013 8:03 PM
  • Hi,

    >> Can I set this behavior using web config?  Can this be used for WCF soap service?

    As Shyam said, it is added in the <endpointBehaviors> tag and apply the behaviorConfiguration for the service. This is used for WCF WEB HTTP services not soap services.

    >>What address doi need to type in browser url to be able to see the operations listed as in asmx?

    When a user browses to a WCF WEB HTTP service and appends "/Help" on to the end of the URL, for example http://localhost:8000/Customers/Help. Please take a look at this document for details.

    #WCF Web HTTP Service Help Page

    http://msdn.microsoft.com/en-us/library/ee230442(v=vs.110).aspx

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by mysti789 Friday, January 25, 2013 5:40 PM
    Thursday, January 24, 2013 1:31 AM
    Moderator