簡體   English   中英

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

[英]WCF REST GET returns “Endpoint not found”

所以我試圖用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>

我在這里錯過了什么?

您打算使用ASP.NET Ajax來調用該服務嗎? 如果沒有,則不應使用<enableWebScript>行為,而應使用<webHttp>行為。

此外,您應該刪除<serviceMetadata>行為,因為您不會從服務中公開WSDL。

所以一切都設置得很好。 我問的端點地址不正確。 它應該是http://localhost:8733/Design_Time_Addresses/RESTfulTest/Service1/json/GetText我不知道應該將函數名添加到地址中,這就是重點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM