【问题标题】:WCF REST GET returns "Endpoint not found"WCF REST GET 返回“找不到端点”
【发布时间】:2017-03-30 13:38:23
【问题描述】:

所以我正在尝试使用 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>

我在这里错过了什么?

【问题讨论】:

    标签: c# rest wcf


    【解决方案1】:

    您打算使用 ASP.NET Ajax 来调用服务吗?如果不是,您不应该使用&lt;enableWebScript&gt; 行为,而应该使用&lt;webHttp&gt; 行为。

    此外,您可能应该删除 &lt;serviceMetadata&gt; 行为,因为您不会从您的服务中公开 WSDL。

    【讨论】:

    • 我已经尝试过使用&lt;webHttp&gt;,但没有帮助。实际上我稍后会使用 WSDL。我发布的代码是更大项目的简化版本,但我仍然无法让 REST 服务在那里工作。也许我没有权限或类似的东西?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多