C# WCF web服务找不到终结点元素

C# WCF web服务找不到终结点元素,c#,wcf,wcf-rest,C#,Wcf,Wcf Rest,我使用以下方法创建了一个WCF Restful服务 并将其与SQLServerDB连接以获取数据,该服务已创建并运行,但问题是它找不到端点元素 这是我的密码 EventDataContract using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Web; namespace WCFEventsSchedule

我使用以下方法创建了一个WCF Restful服务 并将其与SQLServerDB连接以获取数据,该服务已创建并运行,但问题是它找不到端点元素 这是我的密码 EventDataContract

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

namespace WCFEventsSchedule
{
    [DataContract]
    public class EventDataContract
    {
        [DataMember]
        public int EventID { get; set; }
        [DataMember]
        public string Text { get; set; }
        [DataMember]
        public DateTime Start_Date { get; set; }
        [DataMember]
        public DateTime End_Date { get; set; }
        [DataMember]
        public int Room_Id { get; set; }
        [DataMember]
        public int User_Id { get; set; }
    }
}
IEventService

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

namespace WCFEventsSchedule
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IEventService" in both code and config file together.
    [ServiceContract]
    public interface IEventService
    {
        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetAllEvents/")]
        List<EventDataContract> GetAllEvent();

        [OperationContract]
        [WebGet(RequestFormat = WebMessageFormat.Json,
           ResponseFormat = WebMessageFormat.Json,
           UriTemplate = "/EventDetails/{EventID}")]
        EventDataContract EventDetails(string EventID);
    }
}
稍后我将使用WCF在Windows窗体应用程序上显示这些数据

更新的错误因素添加[ServiceBehavior(IncludeExceptionDetailInFaults=true)]

    Le serveur a rencontré une erreur lors du traitement de la demande. Le message d'exception est 'Un objet qui autorise la valeur Null doit posséder une valeur.'. Pour plus d'informations, consultez les journaux du serveur. La trace de la pile d'exception est :

à System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) à System.Nullable`1.get_Value() à WCFEventsSchedule.EventService.<>c__DisplayClass2.<GetAllEvent>b__1(Events x) dans c:\Users\juste 3al faza\Desktop\Scheduler.MVC5\WCFEventsSchedule\EventService.svc.cs:ligne 31 à System.Collections.Generic.List`1.ForEach(Action`1 action) à WCFEventsSchedule.EventService.GetAllEvent() dans c:\Users\juste 3al faza\Desktop\Scheduler.MVC5\WCFEventsSchedule\EventService.svc.cs:ligne 29 à SyncInvokeGetAllEvent(Object , Object[] , Object[] ) à System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) à System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) à System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
Le serveur a rencontractérer lors du traitement de la demande。“例外情况”的消息是自动发送的,不允许在任何情况下发送。”。再加上一些信息,服务记者领事。例外情况下的桩追踪:
a System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)a System.Nullable`1.get_Value()a WCFEventsSchedule.EventService.c_uDisplayClass2.b_u1(Events x)dans c:\Users\juste 3al faza\Desktop\Scheduler.MVC5\WCFEventsSchedule\EventService.svc.cs:Aligne 31 a System.Collections.Generic.List`1.ForEach(Action`1 Action)操作a wcfeventschedule.EventService.GetAllEvent()dans c:\Users\juste 3al faza\Desktop\Scheduler.MVC5\wcfeventschedule\EventService.svc.cs:ligne 29 a SyncInvokeGetAllEvent(Object,Object[],Object[])a System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(对象实例,对象[]输入,对象[]输出)§System.ServiceModel.Dispatcher.DispatcherOperationRuntime.InvokeBegin(MessageRpc&rpc)§System.ServiceModel.Dispatcher.ImmutableDispatcherRuntime.ProcessMessage5(MessageRpc&rpc)§System.ServiceModel.Dispatcher.ImmutableDispatcherRuntime.ProcessMessage41(MessageRpc&rpc)§System.ServiceModel.Dispatcher.ImmutableDispatcherDispatcherRuntime.ProcessMessage4(MessageRpc&rpc)áSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&rpc)áSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&rpc)áSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&rpc)a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&rpc)a System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&rpc)a System.ServiceModel.Dispatcher.MessageRpc.Process(布尔等操作上下文集)

我不确定问题出在哪里,但我怀疑您的
web.config
文件有问题

阅读,以便更清晰地演练


它清楚地显示了
web.config
的两个部分,您需要对这两个部分进行更改,以使其正常工作。

只要WCF服务出现任何问题,这个问题就会出现。 因此,要查看有关该问题的更多详细信息,您需要在servicedebug标记中将exceptiondetailinfaults属性包含到true

编辑

对于那些不懂法语的人,这里是错误的解释


服务器在处理请求时遇到错误 异常消息为“可为null的对象应具有值。” 。有关详细信息,请检查服务器日志。跟踪 异常堆栈是:

System.ThrowHelper.ThrowInvalidOperationException(例外资源 资源)到System.Nullable1.get_值()到 wcfeventschedule.EventService.c__DisplayClass2. b__1(事件x)

这意味着在GetAllEvent()中,您试图分配空值。 若您在那个点上放置一个调试器,您可能会发现哪一行正在抛出异常


(提示:主要是那些不应该为空的值)

访问URL时看到的消息服务器在处理请求时遇到错误。有关详细信息,请查看服务器日志。我在添加IncludeExceptionDetailinFaults后更新了错误问题。就是这样,最后两个值返回null,我对其进行了注释,结果正常
    <?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=6.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="WCFEventsSchedule.EventService" behaviorConfiguration="serviceBehavior" >
        <endpoint address=""
                  binding="webHttpBinding"
                  contract="WCFEventsSchedule.IEventService"
                  behaviorConfiguration="web">

        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <!-- 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>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="webHttpBinding" 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="SchedulerEntities" connectionString="metadata=res://*/Model.EventsModel.csdl|res://*/Model.EventsModel.ssdl|res://*/Model.EventsModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\Scheduler.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
    CREATE TABLE [dbo].[Events] (
    [id]         INT      IDENTITY (1, 1) NOT NULL,
    [text]       TEXT     COLLATE Cyrillic_General_CI_AS NULL,
    [start_date] DATETIME NOT NULL,
    [end_date]   DATETIME NOT NULL,
    [room_id]    INT      NULL,
    [user_id]    INT      NULL,
    CONSTRAINT [PK_Events] PRIMARY KEY CLUSTERED ([id] ASC)
);
    Le serveur a rencontré une erreur lors du traitement de la demande. Le message d'exception est 'Un objet qui autorise la valeur Null doit posséder une valeur.'. Pour plus d'informations, consultez les journaux du serveur. La trace de la pile d'exception est :

à System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) à System.Nullable`1.get_Value() à WCFEventsSchedule.EventService.<>c__DisplayClass2.<GetAllEvent>b__1(Events x) dans c:\Users\juste 3al faza\Desktop\Scheduler.MVC5\WCFEventsSchedule\EventService.svc.cs:ligne 31 à System.Collections.Generic.List`1.ForEach(Action`1 action) à WCFEventsSchedule.EventService.GetAllEvent() dans c:\Users\juste 3al faza\Desktop\Scheduler.MVC5\WCFEventsSchedule\EventService.svc.cs:ligne 29 à SyncInvokeGetAllEvent(Object , Object[] , Object[] ) à System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) à System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) à System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)