WCF REST GET返回“未找到端点”

时间:2017-03-30 13:38:23

标签: c# rest wcf

所以我试图用REST GET创建一个非常基本的WCF服务,但只有“找不到端点”。我通过Postman App发送GET来解决:

http://localhost:8733/Design_Time_Addresses/RESTfulTest/Service1/json

服务由IIS托管;这是我的所有代码:

namespace RESTfulTest
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebGet]
        string GetText();
    }
}

namespace RESTfulTest
{
    [ServiceBehavior(InstanceContextMode =InstanceContextMode.Single)]
    public class Service1 : IService1
    {
        public string GetText()
        {
            return "Hello REST";
        }
    }

}

和App.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="RESTfulTest.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/RESTfulTest/Service1/" />
          </baseAddresses>
        </host>
        <endpoint address="json" binding="webHttpBinding"  behaviorConfiguration="jsonBehavior" contract="RESTfulTest.IService1"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="jsonBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

  </system.serviceModel>

</configuration>

我在这里缺少什么?

2 个答案:

答案 0 :(得分:0)

您打算使用ASP.NET Ajax来调用该服务吗?如果没有,则不应使用<enableWebScript>行为,而应使用<webHttp>行为。

此外,您应该删除<serviceMetadata>行为,因为您不会从服务中公开WSDL。

答案 1 :(得分:0)

所以一切都设置得当。我问的端点地址不正确。它应该是http://localhost:8733/Design_Time_Addresses/RESTfulTest/Service1/json/GetText 我不知道应该将函数名称添加到地址中,这就是重点。

相关问题