【问题标题】:Wcf Service Failed to found the End Point on Local HostWcf 服务无法在本地主机上找到端点
【发布时间】:2017-12-04 03:01:23
【问题描述】:

我正在使用 wcf Rest Service 到 Angular JS Application 中。我创建了几种方法来执行操作。首先,我有带有类库项目的 wcf 服务,并且我创建了另一个 wcf 服务项目来在本地 IIS 中托管它。 当我在本地主机上运行 wcf 服务时,它工作正常,但问题出在 url 上,当我输入方法名称时,它会抛出 End point not found 的异常。例如http://localhost:52098/HalifaxIISService.svc/GetCustomers// 错误未找到端点。

这是我的界面..

  [OperationContract]

        [WebInvoke(Method = "POST",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "/GetCustomers")]
        string GetCustomers(string prefix);

        [OperationContract]
       [WebInvoke(Method = "POST",
       RequestFormat = WebMessageFormat.Json,
       ResponseFormat = WebMessageFormat.Json,
       UriTemplate = "/GetAccountDetails")]
        bool GetAccountDetails(string Account_Number);

这是类库项目中的 app.cong 文件。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DBCS" connectionString="Data Source=;Initial Catalog=HalifaxDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
  <add name="HalifaxDatabaseEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=HalifaxDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="HalifaxWCFProject.HalifaxService">
        <endpoint address="" binding="webHttpBinding" contract="HalifaxWCFProject.IHalifaxService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/HalifaxWCFProject/HalifaxService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这是 IIS 的 service.svc 代码。

<%@ ServiceHost Language="C#" Debug="true" Service="HalifaxWCFProject.HalifaxService"%>

这是 .svc 文件的 web.config..

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="DBCS" connectionString="Data Source=;Initial Catalog=HalifaxDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="HalifaxDatabaseEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=;initial catalog=HalifaxDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.serviceModel>
    <services>
      <service name="HalifaxWCFProject.HalifaxService" behaviorConfiguration="mexBehaviour">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="" behaviorConfiguration="REST" contract="HalifaxWCFProject.IHalifaxService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="REST">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这是屏幕截图。 我在 web.config 文件中定义了终点。我想知道我收到了 End point not Found 这个错误。

【问题讨论】:

    标签: c# web-services wcf iis


    【解决方案1】:

    您收到“未找到端点”错误,因为您定义了 HTTP Post 端点。因此,您无法在 Web 浏览器中测试它们,因为它会发送 HTTP Get 请求。

    如果您希望在不编写任何代码的情况下测试您的服务,请使用Fiddler's Composer 功能发送 HTTP Post 请求。

    Fiddler Screenshot

    或者更改 WebInvoke 属性以允许 HTTP Get 请求。

    [WebInvoke(Method = "GET",
      RequestFormat = WebMessageFormat.Json,
      ResponseFormat = WebMessageFormat.Json,
      UriTemplate = "/GetCustomers")]
    

    【讨论】:

    • 为了访问 get 请求我还需要做哪些更改
    • 我已经修改了我的答案,以解释如何启用网络浏览器来测试您的服务方法。
    【解决方案2】:

    你不能尝试 Post 方法

    【讨论】:

      猜你喜欢
      • 2013-03-03
      • 2019-08-29
      • 2011-10-19
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多