繁体   English   中英

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

[英]WCF Service “Endpoint not found” error

我正在尝试创建一个以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的一个答案表明的,但似乎没有任何效果。

我发现了问题。 我在web.config文件中以及在UriTemplate中为端点指定了一个名称,在{id}之前添加了json /。 我需要删除其中之一,然后它才能工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM