【问题标题】:WcfTestClient: Failed to add a service. Service metadata may not be accessibleWcfTestClient: 添加服务失败。服务元数据可能无法访问
【发布时间】:2016-12-14 23:30:28
【问题描述】:

一开始对不起我的英语。

我知道这个问题已经有了答案,但没有一个对我有用。 我正在尝试连接到我的数据库。

我正在努力:

  • Microsoft Visual Studio Community 2015 版本 14.0.25431.01 更新 3。
  • Microsoft .NET Framework 版本 4.6.01586

我已经检查了工具->选项->项目和解决方案->Web 项目->为网站和项目使用 64 位版本的 IIS Express。

我的代码来自 View Markup (Service1.svc):

这是我的 Web.config

<?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=XXXXXXXXXXXX" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  </system.web>
  <system.serviceModel>
    <services>   
      <service name="WCFconnection.Service1"
           behaviorConfiguration="metadataBehavior">
        <endpoint address="" binding="basicHttpBinding" contract="WCFconnection.IService1" />
        <endpoint address="basic" binding="basicHttpBinding" contract="WCFconnection.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="localhost:23233/Service1.svc"
              binding="basicHttpBinding" 
              contract="WCFconnection.IService1"
              />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior  name="metadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
        <behavior  name="DefaultBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <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">
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <directoryBrowse enabled="true" />
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <connectionStrings>
    <add name="ZPIEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=XXXXXX-XXXXXX;initial catalog=XXXXXX;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="ConStr" connectionString="Data Source=XXXXXXX-XXXXXXXX\XXXXXXX;Initial Catalog=XXXXXXX;Integrated Security=True"/>
  </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>

当我访问网站并将 localhost:23233 放入地址时,我可以看到所有文件,还有我的 Service1.svc。但是如果我尝试制作 WcfTestClient 我得到了错误:

添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。

错误:无法从http://localhost:23233/ 获取元数据如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布...

请帮帮我。

【问题讨论】:

    标签: c# xml wcf


    【解决方案1】:

    根据 WcfTestClient 给您的错误,您没有提供完整的端点 url。

    您正在添加http://localhost:23233/

    你应该添加http://localhost:23233/Service1.svc

    【讨论】:

    • 但是在 Web.config 中已经是 我应该在其他地方提供这个端点吗?
    • 您的 Wcf service 配置似乎没问题。失败的是你如何将它添加到 WcfTestClient (或者你使用它的任何其他地方,我猜)。当您打开 WcfTestClient 并点击“添加”以添加新的服务端点时,您应该传递完整的端点 url,而不仅仅是地址和端口。这是因为您可以在一个地址和端口上拥有多个端点。
    • 我按照你提到的做了,但我有同样的错误:*错误:无法从 localhost:23233/Service1.svc 获取元数据如果这是你有权访问的 Windows (R) Communication Foundation 服务,请检查您已在指定地址启用元数据发布。 *
    • 好吧,现在很奇怪 - 如果我从 Web.config 中删除所有端点,那么 WcfTestClient 工作正常......但我认为它不应该保持这样......应该吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    相关资源
    最近更新 更多