WCF REST service client call mapped to invalid Uris

I have a WCF REST service, very simple, for example:

[ServiceContract]
    public interface ITestService
    {
        [OperationContract]
        [WebInvoke(
           Method = "GET",
           UriTemplate = "getNumber")]
         int GetSomeNumber();
    }

public class TestService : TestServiceApp.ITestService
    {
        public int GetSomeNumber()
        {
            return 5;
        }
    }

It is configured as follows:

<services>
      <service name="TestServiceApp.TestService">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="restBehaviour" contract="TestServiceApp.ITestService" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="restBehaviour">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

It works fine in the browser using the specified Uri pattern:

http://localhost:52602/TestService.svc/getnumber.

I configured my client as follows:

 <client>
      <endpoint name="TstSvc" address="http://localhost:52602/TestService.svc" binding="webHttpBinding" contract="TstSvc.ITestService" behaviorConfiguration="restBehaviour"/>
    </client>

  <behaviors>
    <endpointBehaviors>
      <behavior name="restBehaviour">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

When I call the service with the following code:

    using (WebChannelFactory<ITestService> factory = new WebChannelFactory<ITestService>("TstSvc"))
    {
        var svc = factory.CreateChannel(); 
        svc.GetSomeNumber();
    }

I get an error:

"There was no listening to endpoints in http://localhost:52602/TestService.svc/GetSomeNumberthat could receive the message."

I suspect that for some reason my calls using the GetSomeNumber method do not display correctly in uri / getnumber. What for? How can I fix it that I missed?

+3
source share
1 answer

, , , ITestService WebChannelFactory.

, WebInvoke. WebInvoke ServiceContract (), WebChannelFactory URI REST. WebInvoke (), WebChannelFactory OperationContract, .

0

All Articles