WCF服务“未找到端点”错误

时间:2017-01-06 08:44:00

标签: c# wcf

我正在尝试创建一个以JSON格式返回数据的RESTful服务,但是当我在浏览器中打开它时,它会显示“找不到端点”。

我的web.config看起来像这样

<system.serviceModel>
<services>
  <service name="RestService.HelloWorldService">
    <!--<endpoint address="" binding="basicHttpBinding" behaviorConfiguration="REST"  contract="RestService.IHelloWorldService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" behaviorConfiguration="REST" contract="RestService.IHelloWorldService" />-->
    <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="REST"  contract="RestService.IHelloWorldService" />        
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:52478/HelloWorldService.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="REST">
      <webHttp/>
    </behavior>
  <!--<behavior name="SOAPDemoEndpointBehavior">
  <soapProcessing/>
</behavior>-->
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior>          
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>          
    </behavior>
  </serviceBehaviors>
</behaviors>  
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

这是代码

[ServiceContract]
public interface IHelloWorldService
{
    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "json/{id}")]
    string JsonData(string id);
}

我甚至尝试启动项目(通过F5或Ctrl F5)然后导航到页面,因为stackoverflow上的一个答案提示,但似乎没有任何工作。

1 个答案:

答案 0 :(得分:3)

我发现了问题。我已经在web.config文件中为地址指定了地址,并且在UriTemplate中我在{id}之前添加了json /。我需要删除其中一个然后才能工作。

相关问题