2017-01-06 3 views
-1

Я пытаюсь создать службу RESTful, которая возвращает данные в формате Json, но когда я открываю его в своем браузере, он говорит: «Конечная точка не найдена».Ошибка службы WCF «Конечная точка не найдена»

Мой 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 предложил, но ничего не работает.

+0

Почему отрицательный голос? –

ответ

3

Я нашел проблему. Я указал адрес для конечной точки в файле web.config, а также в UriTemplate я добавил json/before {id}. Мне нужно было удалить один из них, а затем он работает.

Смежные вопросы