Question

We've tried to use a very very simple WCF service with a HTTp Get and we can't get it work. We've followed those "guide" but it doesn't work

When we call our service with the following url, we get a page not found error:

http://localhost:9999/Service1.svc/GetData/ABC

The base url (http://localhost:9999/Service1.svc) works fine and returns the wcf service information page correctly.

Those are the steps and code to reproduce our example.

  1. In Visual Studio 2010, create a new "WCF Service Application" Project
  2. Replace the IService interface with this code

      [ServiceContract()]
      public interface IService1
      {
          [OperationContract()]
          [WebInvoke(Method = "GET", 
                     BodyStyle = WebMessageBodyStyle.Bare, 
                     UriTemplate = "GetData/{value}")]
          string GetData(string value);
      }
    
  3. Replace the Service class with this code

    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
    
  4. The web.config look like this

    <system.web>
       <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
      <services>
          <service name="Service1">
              <endpoint address="" binding="webHttpBinding" contract="IService1" behaviorConfiguration="WebBehavior1">
              </endpoint>
          </service>
      </services>
      <behaviors>
          <endpointBehaviors>
              <behavior name="WebBehavior1">
                 <webHttp helpEnabled="True"/>
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    

  5. Press Run and try to call the Get method

If someone get this or something similar working, it would be very kind if you could reply information about the working example.

Thank you very much

Was it helpful?

Solution

I recreated your sample - works like a charm.

One point: do your service contract (public interface IService1) and service implementation (public class Service1 : IService1) exist inside a .NET namespace??

If so, you need to change your *.svc and your web.config to include:

<services>
      <service name="Namespace.Service1">
          <endpoint address="" binding="webHttpBinding" 
                    contract="Namespace.IService1" 
                    behaviorConfiguration="WebBehavior1">
          </endpoint>
      </service>
  </services>

The <service name="..."> attribute and the <endpoint contract="..."> must include the .NET namespace for this to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top