尝试GetById时,WCF REST服务在浏览器中发现端点未找到错误 [英] WCF REST Service giving endpoint not found error in browser when trying to GetById

查看:92
本文介绍了尝试GetById时,WCF REST服务在浏览器中发现端点未找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起

WCF REST服务在json视图中提供完整的表数据,但是当我尝试获取记录GetById时。

它给出了endpoint not fuond错误

请告诉我如何解决它。我是WCF服务的新手

这是web.config

Excuse me
WCF REST Service giving full table data in json view but when i try to get record GetById.
It is giving "endpoint not fuond" error
Please tell me how to resolve it. I am new to WCF Services
Here is web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WCFDB.ServiceContract">
        <endpoint address="" behaviorConfiguration="restfulBehavior" binding="webHttpBinding" bindingConfiguration="" contract="WCFDB.IServiceContract"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/ServiceContract.svc"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restfulBehavior">
          <webHttp helpEnabled="true"/>
        </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>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>
  <connectionStrings>
    <add name="tawaseelEntities" connectionString="metadata=res://*/NewsModel.csdl|res://*/NewsModel.ssdl|res://*/NewsModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=tawaseel;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>



这里是IServiceContract.cs


and here is IServiceContract.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WCFDB
{
    [ServiceContract]
    public interface IServiceContract
    {
        [OperationContract]
        [WebGet (ResponseFormat=WebMessageFormat.Json)]
        List<news> GetNewsList();

        [OperationContract]
        //[WebGet]
        [WebGet(BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "news/{id}")]
        news GetNewsById(string id);
    }
}



这是ServiceContract.svc


Here is ServiceContract.svc

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WCFDB
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ServiceContract" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select ServiceContract.svc or ServiceContract.svc.cs at the Solution Explorer and start debugging.
    public class ServiceContract : IServiceContract
    {
        public List<news> GetNewsList()
        {
            using (tawaseelEntities entities = new tawaseelEntities())
            {
                return entities.news.ToList();
            }
        }
        public news GetNewsById(string id)
        {
            try
            {
                int Nid = Convert.ToInt32(id);
                using (tawaseelEntities entities = new tawaseelEntities())
                {
                    return entities.news.SingleOrDefault(news => news.id == Nid);
                }
            }
            catch
            {
                throw new FaultException("Something went Wrong");
            }
        }
    }
}



这里的网址正常工作

http:// localhost:42813 / ServiceContract.svc / GetNewsList [ ^ ]

这里给出了端点错误

http:// localhost:42813 /ServiceContract.svc/GetNewsById/3 [ ^ ]



提前感谢


and here the url that is working correctly
http://localhost:42813/ServiceContract.svc/GetNewsList[^]
and here that is giving endpoint error
http://localhost:42813/ServiceContract.svc/GetNewsById/3[^]

Thankss in advance

推荐答案

试试这个:

http :// localhost:42813 / ServiceContract.svc / news / 3



并看到:

REST和WCF [ ^ ]



有一个美好的一天。
try this:
http://localhost:42813/ServiceContract.svc/news/3

and see this:
REST and WCF[^]

have a good day.


这篇关于尝试GetById时,WCF REST服务在浏览器中发现端点未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆