0

我开发了小型 WCF 服务,它从表中获取所有记录。它看起来像这样:

IService1.cs

[ServiceContract]
public interface IService1
{
    List<badanieCis> GetRecords();
}

Service1.svc.cs

public List<badanieCis> GetRecords()
{
   przychodniaEntities dataContext = new przychodniaEntities();
   return dataContext.badanieCis.ToList();
}

我收到一条消息:添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据

经过一些研究后,我所做的是更改 svc 文件中的标记:

<%@ ServiceHost Language="C#" Debug="true"
    Service="Harvesting.Service.HarvestingService" CodeBehind="Service1.svc.cs" %>

但还是一无所获。

我的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings>
    <add name="przychodniaEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DAREK-PC\SQLExpress;initial catalog=przychodnia;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
4

1 回答 1

0

您在配置文件中缺少服务定义。你需要类似的东西:

<services>
  <service behaviorConfiguration="..." name="Service1 with namespace">
    <endpoint address="..." name="..." binding="wsHttpBinding" bindingConfiguration="...." contract="IService1 with unterface" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
 <services>
 ...

您可以使用此工具来帮助进行配置。

于 2012-04-04T08:38:44.370 回答