Reputation: 186
I'm trying to create a RESTful service that returns data in Json format but when I open it in my browser it says "Endpoint not found."
My web.config look like this
<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" />
and here is the code
[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json/{id}")]
string JsonData(string id);
}
I've even tried to start the project (via F5, or Ctrl F5) and then navigating to page, as one answer here on stackoverflow suggested that, but nothing seems to work.
Upvotes: 1
Views: 2862
Reputation: 186
I found the problem. I had given the address a name for the endpoint in the web.config file and also in the UriTemplate I added json/ before {id}. I needed to remove one of them and then it works.
Upvotes: 3